Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def hexGenerate(_bytes):
- if type(_bytes) == str:
- for i in range(len(_bytes)//8):
- hexString = ''.join([hex(ord(char)) for char in _bytes[0+i*8: 8+i*8]])
- yield hexString
- elif type(_bytes) == file:
- for i in range(os.path.getsize(_bytes.name)//8):
- hexString = ''.join([hex(ord(char)) for char in _bytes.read(8)])
- yield hexString
- def eggswap(data, key):
- if len(key)%8 != 0: return False, 'Key lenght not equal to 8'
- hex_gen = hexGenerate(data)
- key = ''.join([hex(ord(char)) for char in key])
- key1, key2 = key.split('0x')[1:5], key.split('0x')[5:9]
- for b in key1:
- if len(b) == 1: key1[key1.index(b)] = '0'+b
- for b in key2:
- if len(b) == 1: key2[key2.index(b)] = '0'+b
- result = ''
- for byte in hex_gen:
- byte1, byte2 = byte.split('0x')[1:5], byte.split('0x')[5:9]
- for b in byte1:
- if len(b) == 1: byte1[byte1.index(b)] = '0'+b
- for b in byte2:
- if len(b) == 1: byte2[byte2.index(b)] = '0'+b
- for byte, key in [(byte1, key1), (byte2, key2)]:
- for i in range(4):
- hex1, hex2 = eval('0x'+byte[i][0]), eval('0x'+byte[i][1])
- hex3, hex4 = eval('0x'+key[i][0]), eval('0x'+key[i][1])
- hex5 = 2*hex4-hex1
- if hex5 > 15: hex5 -= 16
- if hex5 < 0: hex5 += 16
- hex5 = hex(hex5)
- hex6 = 2*hex3-hex2
- if hex6 > 15: hex6 -= 16
- if hex6 < 0: hex6 += 16
- hex6 = hex(hex6).replace('0x','')
- result += hex5+hex6
- return ''.join(chr(eval('0x'+i)) for i in result.split('0x')[1:])
- text = open(r'C:\Users\Gabriel\Documents\GADI2\Test\Test.gp')
- key = '_)734hZ/'
- cipher_text = eggswap(text, key)
- open(r'C:\Users\Gabriel\Documents\GADI2\Test\Test.txt', 'w').write(eggswap(cipher_text, key))
Advertisement
Add Comment
Please, Sign In to add comment