Created
February 26, 2018 22:26
-
-
Save back-seat-driver/8c22ba1449f5c3747fa8415273b2fe62 to your computer and use it in GitHub Desktop.
Matryoshka Doll
This file contains 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
def bin_n_bit(dec,n): | |
return(str(format(dec,'0'+n+'b'))) | |
def hex_n_bit(dec,n): | |
return(str(format(dec,'0'+n+'x'))) | |
def xo_set(ip_0,ip_1): | |
to_return=[] | |
for i in range(len(ip_0)): | |
to_return.append(ip_0[i] ^ ip_1[i]) | |
return(to_return) | |
def L_P(SET,n): | |
to_return = [] ; j = 0 | |
while j + n <= len(SET): | |
to_return.append(SET[j:j+n]) | |
j += n | |
return(to_return) | |
def rot(x,n,l): | |
n = n%l | |
return((x>>(l-n))+(x<<n))%(1<<l) | |
def achilles(ip): | |
c_xz=[] | |
for i in range(5): | |
c_xz.append(ip[i] ^ ip[i+5] ^ ip[i+10] ^ ip[i+15] ^ ip[i+20]) | |
for i in range(5): | |
d_xz = c_xz[(i-1)%5] ^ rot(c_xz[(i+1)%5],1,64) | |
for x in range(0,25,5): | |
ip[i+x] = ip[i+x] ^ d_xz | |
return(ip) | |
def neptune(ip): | |
fast_rot=[66,1,62,28,27, | |
36,44,6,55,20, | |
3,10,43,25,39, | |
41,45,15,21,8, | |
18,2,61,56,14] | |
for i in range(25): | |
ip[i] = rot(ip[i], fast_rot[i], 64) | |
return(ip) | |
def pumpkin(ip): | |
index=[0,6,12,18,24, | |
3,9,10,16,22, | |
1,7,13,19,20, | |
4,5,11,17,23, | |
2,8,14,15,21] | |
to_return=[] | |
for i in range(25): | |
for x in range(25): | |
if index[i]==x: | |
to_return.append(ip[x]) | |
return(to_return) | |
def tea(ip): | |
def sf(find_list,set_main): | |
return(set_main.index(find_list)) | |
sm=[[0,0],[1,0],[2,0],[3,0],[4,0], | |
[0,1],[1,1],[2,1],[3,1],[4,1], | |
[0,2],[1,2],[2,2],[3,2],[4,2], | |
[0,3],[1,3],[2,3],[3,3],[4,3], | |
[0,4],[1,4],[2,4],[3,4],[4,4]] | |
to_return=[] | |
for i in range(25): | |
to_return.append(ip[i] ^ | |
~ip[sf([(sm[i][0]+1)%5,sm[i][1]],sm)] & | |
ip[sf([(sm[i][0]+2)%5,sm[i][1]],sm)]) | |
return(to_return) | |
def jedi_flip(ip,i_r): | |
RC=[0xd8eff8dc1fb37819, | |
0xa602f2265cbaa2d3, | |
0xa8118a7159a86fd3, | |
0xb76915a17084d769, | |
0xc6589e48faf71e66, | |
0xf9bbfa89cfd7fd7b, | |
0x9d71960dae9e3637, | |
0x8c85d7fa8ef1fa42, | |
0x0a40ca5d07c86537, | |
0x495e08484b01a132, | |
0x7e661bfa93e9068c, | |
0xecb2f2867b33f5fb, | |
0xd7f24e5ff930421e, | |
0x4aca6e72026b5836, | |
0x16585fe656768844, | |
0x4d3da4efc6fcd4c7, | |
0x2b7fec306a5aa381, | |
0x57453054d6c41b6e, | |
0xe0a21eed88b74148, | |
0x1fbe2234ec6cdcca, | |
0xe415289c8e42386b, | |
0x046ca7541385dc78, | |
0x5b5b1f28e698025d, | |
0xdf7abf4247cf6e8f] | |
ip[0]=ip[0] ^ RC[i_r] | |
return(ip) | |
def boost(ip): | |
to_return=[] | |
for i in range(25): | |
to_return.append(int(ip[i],2)) | |
return(to_return) | |
def booster(op): | |
to_return=[] | |
for i in range(25): | |
to_return.append(bin_n_bit(op[i],'64')) | |
return(to_return) | |
def copy_cat(output_len): | |
if output_len==224: | |
return(1152) | |
if output_len==256: | |
return(1088) | |
if output_len==384: | |
return(832) | |
if output_len==512: | |
return(576) | |
def pad(x,m): | |
j=(-m-2)%x | |
return('1'+'0'*j+'1') | |
def message_processing(bit_string,digest_len): | |
if len(bit_string)!=copy_cat(digest_len): | |
msg_bs = bit_string + '01' | |
p = msg_bs + pad(copy_cat(digest_len),len(msg_bs)) | |
if len(bit_string)==copy_cat(digest_len): | |
p=bit_string | |
to_split = L_P(p,8) | |
new_hex=[] | |
for i in range(len(to_split)): | |
new_hex.append(hex_n_bit(int(to_split[i],2),'2')) | |
back_append = 200-len(new_hex) | |
new_hex = L_P(new_hex+['00']*back_append,8) | |
set_hold=[] | |
for i in range(len(new_hex)): | |
insert='' | |
for x in range(len(new_hex[i])): | |
insert+=new_hex[i][x] | |
set_hold.append(bin_n_bit(int(insert,16),'64')) | |
return(set_hold) | |
def message_bit_return(string_input): | |
bit_list='' | |
for i in range(len(string_input)): | |
bit_list+=bin_n_bit(ord(string_input[i]),'8') | |
return(bit_list) | |
def main_bit_set(bit_string,digest_len): | |
#All this function does is take the primary sha_3 seed | |
#and return the block chain to be iterated to hashing. | |
front_append=L_P(bit_string,copy_cat(digest_len)) | |
back_string='' | |
for i in range(len(bit_string)%copy_cat(digest_len)): | |
back_string+=bit_string[-(i+1)] | |
back_string=back_string | |
return(front_append+[back_string]) | |
def nest(bit_string,digest_len): | |
if len(bit_string) < copy_cat(digest_len): | |
x = message_processing(bit_string,digest_len) | |
stat_test=[] | |
for i in range(24): | |
x = booster(jedi_flip(tea(pumpkin(neptune(achilles(boost(x))))),i)) | |
return(x) | |
if len(bit_string) >= copy_cat(digest_len): | |
set_main=main_bit_set(bit_string,digest_len) | |
x=message_processing(set_main[0],digest_len) | |
for i in range(24): | |
x = booster(jedi_flip(tea(pumpkin(neptune(achilles(boost(x))))),i)) | |
for c in range(len(set_main)-1): | |
var_1=message_processing(set_main[c+1],digest_len) | |
var_2=booster(xo_set(boost(x),boost(var_1))) | |
for i in range(24): | |
var_2 = booster(jedi_flip(tea(pumpkin(neptune(achilles(boost(x))))),i)) | |
x=var_2 | |
return(x) | |
def Matryoshka_Doll(a_string,digest_len): | |
def str_concat(list_of_strings): | |
to_return='' | |
for i in range(len(list_of_strings)): | |
to_return+=list_of_strings[i] | |
return(to_return) | |
to_return='' | |
for i in range(len(a_string)): | |
to_return+=message_bit_return(a_string[i]) | |
return(hex_n_bit(int(str_concat(nest(to_return,digest_len)),2),'400')[0:digest_len/4]) | |
print(Matryoshka_Doll('test',256)) | |
#ec2cf2460ec67d0112e8762c4b15cc86eaaac50206c3a715e3f50574af4bd5d1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment