首页 > 其他分享 >对称加密乱记

对称加密乱记

时间:2023-08-08 20:35:22浏览次数:31  
标签:乱记 加密 length seed key print 对称 ot data

块密码

mt19937

困难的,难逆向的,脚本小子的。

RC4

from Cryptodome.Cipher import ARC4
 
def encrypt(key, data):
    cipher = ARC4.new(key)
    return cipher.encrypt(data)
 
def decrypt(key, data):
    cipher = ARC4.new(key)
    return cipher.decrypt(data)
key = b'secretkey'
data = b'hello, world'
 
# 加密
encrypted_data = encrypt(key, data)
print("加密后的数据:" + str(encrypted_data))
 
# 解密
decrypted_data = decrypt(key, encrypted_data)
print("解密后的数据:" + str(decrypted_data, encoding='utf-8'))

lcg

这个感觉自己学的挺好的(

直接放一个\(a,b,m\)都要求的题

from Crypto.Util.number import *
from gmpy2 import *
"""
flag = b'Spirit{****************************************}'

plaintext = bytes_to_long(flag)
length = plaintext.bit_length()

a = getPrime(length)
b = getPrime(length)
n = getPrime(length)

seed = plaintext
output = []
for i in range(10):
    seed = (a*seed+b)%n
    output.append(seed)

print("output = ",output)
"""
ot =  [9997297986272510947766344959498975323136012075787120721424325775003840341552673589487134830298427997676238039214108, 4943092972488023184271739094993470430272327679424224016751930100362045115374960494124801675393555642497051610643836, 6774612894247319645272578624765063875876643849415903973872536662648051668240882405640569448229188596797636795502471, 9334780454901460926052785252362305555845335155501888087843525321238695716687151256717815518958670595053951084051571, 2615136943375677027346821049033296095071476608523371102901038444464314877549948107134114941301290458464611872942706, 11755491858586722647182265446253701221615594136571038555321378377363341368427070357031882725576677912630050307145062, 7752070270905673490804344757589080653234375679657568428025599872155387643476306575613147681330227562712490805492345, 8402957532602451691327737154745340793606649602871190615837661809359377788072256203797817090151599031273142680590748, 2802440081918604590502596146113670094262600952020687184659605307695151120589816943051322503094363578916773414004662, 5627226318035765837286789021891141596394835871645925685252241680021740265826179768429792645576780380635014113687982]
t=[0]*10
for i in range(9):
	t[i]=ot[i+1]-ot[i]
m=gcd((t[7]*t[5]-t[6]*t[6]),(t[6]*t[4]-t[5]*t[5]))
a=((ot[9]-ot[8])*invert(ot[8]-ot[7],m))%m
b=(ot[9]-a*ot[8])%m
ans=((ot[0]-b)*invert(a,m))%m
print(long_to_bytes(ans))

上面唯一没有提到式子这里补充一下

\(X_{n}=(a^{-1}(X_{n+1}-b))%\mod m\)

块密码

明天讲。

标签:乱记,加密,length,seed,key,print,对称,ot,data
From: https://www.cnblogs.com/master-lio/p/17615298.html

相关文章

  • 如何爆破js加密后的密码?
    如何爆破js加密后的密码?1、首先burp中安装插件:https://github.com/whwlsfb/BurpCrypto 安装插件完毕后,分析进行js加密的算法。2、分析加密过程:找到相关的加密算法的代码,分析代码逻辑。可以从登录界面的网站源代码里搜encrypt或者crypt字段。根据这段代码,最终passWord字段......
  • 加密货币钱包列表
    YoroiWalletTronlinkNiftyWalletMetamaskMathWalletCoinbaseBinanceChainGuardaWalletEqualWalletJaxxxLibertyBitAppWalletiWalletWombatAtomicWalletMewCxGuildWalletSaturnWalletRoninWalletTerraStationHarmonyWalletCoin98WalletTonCrystalKardiaC......
  • frida hook md5加密类
    importfrida,sys​defon_message(message,data):  ifmessage['type']=='send':    print("[*]{0}".format(message['payload']))  else:    print(message)​​jscode="""//打印调用堆栈functionprintsta......
  • 基于md5加密的模拟管理员登录系统
    importosimportpandasaspddefmd5(string:str=''):  importhashlib  md5=hashlib.md5()  md5.update(string.encode('utf-8'))  returnmd5.hexdigest()#In[1]:defmd5(string:str=''):^M#  ...:  importhash......
  • 番茄字体加密
    提供一个思路 然后一个一个去补 代码 importjsonfromfontTools.ttLibimportTTFontimportrefromlxmlimportetreewithopen('t.xml','r',encoding='utf-8')asfp:x=fp.read().encode('utf-8')xl=etree.HTML(x)k={......
  • [golang]使用mTLS双向加密认证http通信
    前言假设一个场景,服务端部署在内网,客户端需要通过暴露在公网的nginx与服务端进行通信。为了避免在公网进行http明文通信造成的信息泄露,nginx与客户端之间的通信应当使用https协议,并且nginx也要验证客户端的身份,也就是mTLS双向加密认证通信。这条通信链路有三个角色:服务端、N......
  • JAVA ASE 默认随机 sha1 key加密
    使用原始的方法publicstaticStringEncryptEncode(Stringcontent,String...key)throwsException{StringencryptKey="audaque2018";KeyGeneratorkeyGenerator=KeyGenerator.getInstance("AES");SecureRandomrandom=......
  • TSINGSEE青犀视频安防监控视频平台加密机的详细使用与操作步骤
    我们在此前的文章中介绍过不少TSINGSEE青犀视频安防监控视频平台关于加密机授权操作及相关疑问解答,感兴趣的用户可以翻阅往期的文章进行了解。由于新用户咨询该方面的问题较多,今天我们再来介绍一下操作步骤。注意:加密机是依据IP授权,因此授权的前提是加密机的网络与要授权的视频监控......
  • MD5加密
    AandroidMD5加密/***MD5加密**@paramstr*@return*/publicstaticStringgetMD5Str(Stringstr){MessageDigestmessageDigest=null;try{messageDigest=MessageDigest.getInstance("MD5"......
  • 22加密模块/日志模块
    购物程序代码作业importosimportjson#获取执行文件所在的路径current_path=os.path.dirname(__file__)#拼接db文件夹的路径data_path=os.path.join(current_path,'db')ifnotos.path.exists(data_path):#如果文件夹路径不存在os.mkdir(data_path)#......