arc4-drop8192-rot256.py
import sys
def ksa(key):
s = []
for i in range(0, 256):
s.append(i)
j = 0
for i in range(0, 256):
j = ((j + s[i] + ord(key[i % len(key)])) % 256)
t = s[i]
s[i] = s[j]
s[j] = t
return s
def rot(inp, num):
t = (inp + num)
while (t > 255):
t = (t % 256)
while (t < 0):
t = (t + 256)
return t
def cipher(inp, key, dir):
i = 0
j = 0
x = 0
s = ksa(key)
o = ""
while (x < 8192):
i = ((i + 1) % 256)
j = ((j + s[i]) % 256)
t = s[i]
s[i] = s[j]
s[j] = t
x += 1
x = 0
while (x < len(inp)):
i = ((i + 1) % 256)
j = ((j + s[i]) % 256)
t = s[i]
s[i] = s[j]
s[j] = t
k = s[(s[i] + s[j]) % 256]
o = (o + chr(rot(ord(inp[x]), dir * k)))
x += 1
return o
sys.stdout.write(cipher(sys.stdin.read(), sys.argv[1], int(sys.argv[2])))
$ echo "secret messageAAAA" | python arc4-drop8192-rot256.py "secret kez" "1" | hexdump -C
00000000 0c 06 1d 6c 9f 24 cb 6e 10 5f 5d 87 10 2e 2b 9a |...l.$.n._]...+.|
00000010 90 1c b2 |...|
00000013
$ echo "secret messageAAAA" | python arc4-drop8192-rot256.py "secret kez" "1" | python arc4-drop8192-rot256.py "secret kez" "-1"
secret messageAAAA
Like this:
Like Loading...
Related