· 9 years ago · Aug 29, 2016, 07:12 AM
1def fuscate(string_in, secret_key):
2 2 length = len(secret_key)
3 3
4 4 if len(string_in) > length:
5 5 print("fuck off mate")
6 6
7 7 ## make a result list to contain our characters
8 8 result = [' ' for x in range(length)]
9 9
10 10 ## pad out extra spaces in our input; avoids index errors cheap and easy
11 11 string_in = string_in.ljust(length, " ")
12 12
13 13 for i in range(length):
14 14 a = ord(string_in[i]) ## the ascii value of string_in[i]
15 15 k = ord(secret_key[i]) ## the ascii value of secret_key[i]
16 16 result[i] = chr(a^k) ## the character of those XOR'd
17 17
18 18 return "".join(result) ## join those to a string
19 19
20 20
21 21 ## dearest op, this will produce characters outside of the usual ascii range
22 22
23 23 a = "abc"
24 24 key = "quickbrownfox"
25 25
26 26 b = fuscate(a, key)
27 27
28 28 print(b)00093480830062687949
29 29
30 30 c = fuscate(b, key)
31 31
32 32 print(c)