mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-05 08:10:40 -07:00
Initial commit for GitHub migration based on spice2x-25-03-03
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
def rc4_ksa(key):
|
||||
n = len(key)
|
||||
j = 0
|
||||
s_box = list(range(256))
|
||||
for i in range(256):
|
||||
j = (j + s_box[i] + key[i % n]) % 256
|
||||
s_box[i], s_box[j] = s_box[j], s_box[i]
|
||||
return s_box
|
||||
|
||||
|
||||
def rc4_prga(s_box):
|
||||
i = 0
|
||||
j = 0
|
||||
while True:
|
||||
i = (i + 1) % 256
|
||||
j = (j + s_box[i]) % 256
|
||||
s_box[i], s_box[j] = s_box[j], s_box[i]
|
||||
yield s_box[(s_box[i] + s_box[j]) % 256]
|
||||
|
||||
|
||||
def rc4(key):
|
||||
return rc4_prga(rc4_ksa(key))
|
||||
Reference in New Issue
Block a user