Created
February 1, 2020 20:27
-
-
Save pawlos/41bf51a0c43293b718d20ac7363ae270 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
k = "Pl3as_d0"+"n't_cR45"+"h_1n_+h!"+"s_fUnC+1"+"0n" | |
s = "+U]\x93\xa0C\xdd\x14"+"CR}\xe5" | |
print len(k), len(s) | |
b = [] | |
j = 0 | |
cnt = 0xf6 | |
#key scheduling algorithm | |
def KSA(key): | |
keylength = len(key) | |
S = range(cnt) | |
j = 0 | |
for i in range(cnt): | |
j = (j + S[i] + key[i % keylength]) % cnt | |
S[i], S[j] = S[j], S[i] # swap | |
return S | |
#Psudo-random generation algorithm | |
def PRGA(S): | |
i = 0 | |
j = 0 | |
while True: | |
i = (i + 1) % cnt | |
j = (j + S[i]) % cnt | |
S[i], S[j] = S[j], S[i] # swap | |
K = S[(S[i] + S[j]) % cnt] | |
yield K | |
def RC4(key): | |
S = KSA(key) | |
return PRGA(S) | |
a = RC4([ord(x) for x in k]) | |
b = [] | |
l = len(s) | |
i = 0 | |
for c in a: | |
if i >= l: | |
break | |
b.append(chr(ord(s[i]) ^ c)) | |
i += 1 | |
print ''.join(b) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment