网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
05月09日漏签0天
c++吧 关注:613,900贴子:2,110,459
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 7回复贴,共1页
<<返回c++吧
>0< 加载中...

关于加密,解密的函数,有人能把python转成c++程序吗?

  • 只看楼主
  • 收藏

  • 回复
  • 夜色温柔
  • ||
    5
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
因为实在看不懂python程序,逻辑跟不上,不想现学
下面有案例。
有高手来试试吧
# This is anexample program using a 64 bits key
# you may usingPython 3.x to run it
# you areencouraged to write your own program for RC4 since the algorithm is simple
def rc4crypt(data,key):
x = 0
box = list(range(256))
for i in range(256):
x = (x + box[i] + key[i % len(key)]) %256
box[i], box[x] = box[x], box[i]
x = 0
y = 0
out = []
for char in data:
x = (x + 1) % 256
y = (y + box[x]) % 256
box[x], box[y] = box[y], box[x]
out.append(ord(char) ^ box[(box[x] +box[y]) % 256])
return out
defrc4decrypt(data, key):
x = 0
box = list(range(256))
for i in range(256):
x = (x + box[i] + key[i % len(key)]) %256
box[i], box[x] = box[x], box[i]
x = 0
y = 0
out = []
for char in data:
x = (x + 1) % 256
y = (y + box[x]) % 256
box[x], box[y] = box[y], box[x]
out.append(chr(char ^ box[(box[x] +box[y]) % 256]))
return ''.join(out)
data = "thisis a plaintext"
key = [0x12, 0x34,0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]
ciphertext =rc4crypt(data, key)
plaintext =rc4decrypt(ciphertext, key)
print('data :',data)
print('key :',key)
print('ciphertext:', ciphertext)
print('plaintext:', plaintext)
*******************theresults for above program is******************
data : this is aplaintext
key : [18, 52, 86,120, 154, 188, 222, 240]
ciphertext : [111,213, 40, 159, 67, 144, 7, 72, 240, 137, 19, 133, 81, 112, 144, 150, 226, 178,176]
plaintext : thisis a plaintext


  • liamtuan
  • &&
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
先把排版弄好吧,不然只好猜了


义乌市迪丰网络科技
dll修复工具-修复大师解决dll丢失导致的游戏无法启动,应用无法打开系统崩溃等问题;dll综合解决工具下载,一键安装,快速自动修复!
2025-05-09 20:29广告
立即查看
2025-05-09 20:29:15
广告
  • 红藕香残玉簟春
  • <<
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
完全看不懂啊
   ...  .................................................狗对猫说:你猜我口袋里有几块糖? 猫说:猜对了你给我吃吗? 狗点点头:嗯,猜对了两块都给你! 猫咽下口水说:五块!然后,狗笑着把糖放到猫手里,说:我还欠你三块——这不是低智商的笑话,而是,因为爱你,所以允许你的小贪心......猫兴奋的吃了这两块加大量安眠药的糖,昏过去了.然后被小狗日了……
   -
  


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 7回复贴,共1页
<<返回c++吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示