SHA-1 Hashes
Author |
Message |
perds
|
Posted: Sun Dec 04, 2005 10:58 am Post subject: SHA-1 Hashes |
|
|
Just wondering if anyone has used turing to create SHA-1 hashes of strings, and if they wouldn't mind sharing the code. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
MysticVegeta
|
Posted: Sun Dec 04, 2005 11:31 am Post subject: (No subject) |
|
|
Hi, Welcome To compsci.ca
1) I dont know what you mean by SHA-1 hasches.
2) Even if someone did have the program, he/she wouldn't share because it looks like an assignment to me and we will let you work on it first
3) We would be happy to help you with your code. But you have to give it a shot first. |
|
|
|
|
|
Cervantes
|
Posted: Sun Dec 04, 2005 11:49 am Post subject: Re: SHA-1 Hashes |
|
|
perds wrote: Just wondering if anyone has used turing to create SHA-1 hashes of strings
Not to the best of my knowledge. Perhaps wikipedia will help you out though. Particularly the Pseudocode.
Pseudocode: |
//Note: All variables are unsigned 32 bits and wrap modulo 2^32 when calculating
//Initialize variables:
h0 := 0x67452301
h1 := 0xEFCDAB89
h2 := 0x98BADCFE
h3 := 0x10325476
h4 := 0xC3D2E1F0
//Pre-processing:
append a single "1" bit to message
append "0" bits until message length ≡ 448 ≡ -64 (mod 512)
append length of message (before pre-processing), in bits as 64-bit big-endian integer to message
//Process the message in successive 512-bit chunks:
break message into 512-bit chunks
for each chunk
break chunk into sixteen 32-bit big-endian words w(i), 0 ≤ i ≤ 15
//Extend the sixteen 32-bit words into eighty 32-bit words:
for i from 16 to 79
w(i) := (w(i-3) xor w(i-8) xor w(i-14) xor w(i-16)) leftrotate 1
//Initialize hash value for this chunk:
a := h0
b := h1
c := h2
d := h3
e := h4
//Main loop:
for i from 0 to 79
if 0 ≤ i ≤ 19 then
f := (b and c) or ((not b) and d)
k := 0x5A827999
else if 20 ≤ i ≤ 39
f := b xor c xor d
k := 0x6ED9EBA1
else if 40 ≤ i ≤ 59
f := (b and c) or (b and d) or (c and d)
k := 0x8F1BBCDC
else if 60 ≤ i ≤ 79
f := b xor c xor d
k := 0xCA62C1D6
temp := (a leftrotate 5) + f + e + k + w(i)
e := d
d := c
c := b leftrotate 30
b := a
a := temp
//Add this chunk's hash to result so far:
h0 := h0 + a
h1 := h1 + b
h2 := h2 + c
h3 := h3 + d
h4 := h4 + e
digest = hash = h0 append h1 append h2 append h3 append h4 //(expressed as big-endian)
|
You might also want to check out zylum's bitwise operators tutorial. |
|
|
|
|
|
perds
|
Posted: Sun Dec 04, 2005 12:46 pm Post subject: (No subject) |
|
|
dont worry, it's not an assignment, i've already completed the grade 10 and 11 computer science courses
taking the grade 12 comp science course this year, but we're doing java instead of turing, and i dont start that until next semester
i needed this code for my own project that im working on, and since turing is one of the best languages that i know that is able to do this, i thought it'd be easier to complete in turing than in java, since i havent started to learn that yet.
anyways, thx a bunch for this |
|
|
|
|
|
perds
|
Posted: Sun Dec 04, 2005 12:47 pm Post subject: (No subject) |
|
|
after actually thinking about this, i could probably get the job done quite a bit faster in php since it has the function built in. |
|
|
|
|
|
Tony
|
Posted: Sun Dec 04, 2005 4:37 pm Post subject: (No subject) |
|
|
or you know... Ruby I'm using SHA-1 to encrypt user password information in my rails' application |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
|
|