Skip to content

Instantly share code, notes, and snippets.

@sysopfb
Created July 18, 2020 19:19
Show Gist options
  • Select an option

  • Save sysopfb/19aa8e0bdecde60662b7adecdc72b11f to your computer and use it in GitHub Desktop.

Select an option

Save sysopfb/19aa8e0bdecde60662b7adecdc72b11f to your computer and use it in GitHub Desktop.
RC4 algorithm with SBOX extension
def decode_data(data, key, sz):
S = list(range(sz))
S = [x&0xff for x in S]
j = 0
out = []
for i in range(sz):
j = (j + S[i] + ord( key[i % len(key)] )) % sz
S[i] , S[j] = S[j] , S[i]
i = j = 0
for char in data:
i = ( i + 1 ) % sz
j = ( j + S[i] ) % sz
S[i] , S[j] = S[j] , S[i]
out.append(chr(ord(char) ˆ S[(S[i] + S[j]) % sz]))
return ''.join(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment