This page was already viewed 334times
In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographically broken but still widely used hash function which takes an input and produces a 160-bit (20-byte) hash value known as a message digest – typically rendered as a hexadecimal number, 40 digits long. It was designed by the United States National Security Agency, and is a U.S. Federal Information Processing Standard.
It's most often used to verify a file has been unaltered. This is done by producing a checksum before the file has been transmitted, and then again once it reaches its destination. The transmitted file can be considered genuine only if both checksums are identical.
*HistorySHA-1 is only one of the four algorithms in the Secure Hash Algorithm (SHA) family. SHA-0 has a 160-bit message digest (hash value) size and was the first version of this algorithm. Its hash values are 40 digits long. It was published under the name "SHA" in 1993 but wasn't used in many applications because it was quickly replaced with SHA-1 in 1995 due to a security flaw.
SHA-1 is the second iteration of this cryptographic hash function. This one also has a message digest of 160 bits and sought to increase security by fixing a weakness found in SHA-0. However, in 2005, SHA-1 was also found to be insecure. Once cryptographic weaknesses were found in SHA-1, NIST made a statement in 2006 encouraging federal agencies to adopt the use of SHA-2 by the year 2010. SHA-2 is stronger than SHA-1, and attacks made against SHA-2 are unlikely to happen with current computing power.
Create a sha1.py file and insert the following content.
#!/usr/bin/python #Made by RemsFlems. import binascii import struct def int2bytes(i): hex_string = '%x' % i n = len(hex_string) return binascii.unhexlify(hex_string.zfill(n + (n & 1))) def chunks(l, n): return [l[i:i+n] for i in range(0, len(l), n)] def rol(n, b): return ((n << b) | (n >> (32 - b))) & 0xffffffff #initialisation des variables selon la rfc 3174 h0 = 0x67452301 h1 = 0xEFCDAB89 h2 = 0x98BADCFE h3 = 0x10325476 h4 = 0xC3D2E1F0 converted = "" #phrase a hasher motclair = raw_input('\nEntrez le mot ou la phrase a hasher : ') #on traduit le message en binaire for n in range(len(motclair)): converted +='{0:08b}'.format(ord(motclair[n])) #on ajoute 1 binarytemp = converted + "1" binarystring = binarytemp #on remplit de 0 jusqu'a obtenir un multiple de 512 (longueur comprise) while len(binarystring)%512 != 448: binarystring+="0" #on ajoute la longueur et conversion en 64 bits binarystring += '{0:064b}'.format(len(binarytemp) - 1) #ici, le message par blocs de 512 bits a ete cree. #nous allons ensuite pouvoir hasher par bloc de 512 for c in chunks(binarystring, 512): words = chunks(c, 32) w = [0]*80 #on coupe en blocs de 512 bits, on coupe ensuite ces morceaux en blocs de 16*32 bits for n in range(0, 16): w[n] = int(words[n], 2) #on etend enfin ces 16 blocs de 32bits en 80 blocs for i in range(16, 80): w[i] = rol((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1) #on initialise les valeurs de hash a = h0 b = h1 c = h2 d = h3 e = h4 #boucle de hashage #Main loop for i in range(0, 80): if 0 <= i <= 19: f = (b & c) | ((~b) & d) k = 0x5A827999 elif 20 <= i <= 39: f = b ^ c ^ d k = 0x6ED9EBA1 elif 40 <= i <= 59: f = (b & c) | (b & d) | (c & d) k = 0x8F1BBCDC elif 60 <= i <= 79: f = b ^ c ^ d k = 0xCA62C1D6 #rotation algorithmique des termes temp = rol(a, 5) + f + e + k + w[i] & 0xffffffff e = d d = c c = rol(b, 30) b = a a = temp h0 = (h0 + a) & 0xffffffff h1 = (h1 + b) & 0xffffffff h2 = (h2 + c) & 0xffffffff h3 = (h3 + d) & 0xffffffff h4 = (h4 + e) & 0xffffffff print('le mot converti en hash de type sha1 est : ', '%08x%08x%08x%08x%08x' % (h0, h1, h2, h3, h4)) raw_input('\n\nFin\n\n')
Execute the created python file with the following command:
client@linux:#python sha1.py