Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import codecs
- import textwrap
- from math import sin
- import numpy as np
- def notBit (decNum):
- binNum = bin(decNum)[2:]
- newBinNum = ''
- for c in binNum:
- if (c == '0'):
- newBinNum += '1'
- else:
- newBinNum += '0'
- return int(newBinNum, 2)
- def convertToBin (hexNum):
- binNum = ''
- for i in hexNum:
- binNum += format(i, '08b')
- return(binNum)
- def convertToDec (hexNum):
- binNum = ''
- for i in hexNum:
- binNum += format(i, '08b')
- binNum = int(binNum, 2)
- return(binNum)
- def shift (decNum, n):
- binNum = bin(decNum)[2:]
- binNum = binNum[n:]+binNum[:n]
- return int(binNum, 2)
- def F(b,c,d):
- return (b & c)|(notBit(b) & d)
- def G(b,c,d):
- return (b & d)|(notBit(d) & c)
- def H(b,c,d):
- return b ^ c ^ d
- def I(b,c,d):
- return c ^ (notBit(d) | b)
- def K(i,r):
- return int(2**32 * abs(sin(i + 16 * (r - 1))))
- def getTable(i,j):
- table = np.array([[(1,7),(2,12),(3,17),(4,22),(5,7),(6,12),(7,17),(8,22),(9,7),(10,12),(11,17),(12,22),(13,7),(14,12),(15,17),(16,22)],
- [(2,5),(7,9),(12,14),(1,20),(6,5),(11,9),(15,14),(5,20),(10,5),(15,9),(4,14),(9,20),(14,5),(3,9),(8,14),(13,20)],
- [(6,4),(9,11),(12,16),(15,23),(2,4),(5,11),(8,16),(11,23),(14,4),(1,11),(4,16),(7,23),(10,4),(13,11),(16,16),(3,23)],
- [(1,6),(8,10),(15,15),(6,21),(13,6),(4,10),(11,15),(2,21),(9,6),(16,10),(7,15),(14,21),(5,6),(12,10),(3,15),(10,21)]])
- return table[i,j]
- fun = [F, G, H, I]
- name ='Шад'.encode('cp1251')
- name2 = convertToDec(codecs.encode('Шад'))
- hexName = codecs.encode(name, 'hex')
- binName = bin(int.from_bytes(name, byteorder=sys.byteorder))[2:]
- binName += '1'
- for i in range(0,448 - len(binName)):
- binName += '0'
- length = bin(len(binName))[2:]
- for i in range(0,64 - len(length)):
- binName += '0'
- binName += length
- print(hex(int(binName,2))[2:])
- print()
- binName = textwrap.wrap(binName, 32)
- decName = list(map(lambda x: int(x,2), binName))
- a = b'\x67\x45\x23\x01'
- b = b'\xef\xcd\xab\x89'
- c = b'\x98\xba\xdc\xfe'
- d = b'\x10\x32\x54\x76'
- a = startA = convertToDec(a)
- b = startB = convertToDec(b)
- c = startC = convertToDec(c)
- d = startD = convertToDec(d)
- for i in range(0,4):
- for j in range(0,16):
- print(hex(a)[2:])
- print(hex(b)[2:])
- print(hex(c)[2:])
- print(hex(d)[2:])
- print()
- a, b, c, d = d, (shift(fun[i](b, c, d) ^ a ^ decName[getTable(i,j)[0]-1] ^ K(j+1, i+1), getTable(i,j)[1]) ^ b), b, c
- print(hex(a)[2:])
- print(hex(b)[2:])
- print(hex(c)[2:])
- print(hex(d)[2:])
- print()
- a = hex(a ^ startA)[2:]
- b = hex(b ^ startB)[2:]
- c = hex(c ^ startC)[2:]
- d = hex(d ^ startD)[2:]
- print(a)
- print(b)
- print(c)
- print(d)
- print()
- print(d,end = '')
- print(c,end = '')
- print(b,end = '')
- print(a,end = '')
Add Comment
Please, Sign In to add comment