
-----------------------------------
perds
Sun Dec 04, 2005 10:58 am

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.

-----------------------------------
MysticVegeta
Sun Dec 04, 2005 11:31 am


-----------------------------------
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.  :wink:

-----------------------------------
Cervantes
Sun Dec 04, 2005 11:49 am

Re: SHA-1 Hashes
-----------------------------------
Just wondering if anyone has used turing to create SHA-1 hashes of strings
Not to the best of my knowledge.  Perhaps 
//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 &#8801; 448 &#8801; -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 &#8804; i &#8804; 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 &#8804; i &#8804; 19 then
            f := (b and c) or ((not b) and d)
            k := 0x5A827999
        else if 20 &#8804; i &#8804; 39
            f := b xor c xor d
            k := 0x6ED9EBA1
        else if 40 &#8804; i &#8804; 59
            f := (b and c) or (b and d) or (c and d)
            k := 0x8F1BBCDC
        else if 60 &#8804; i &#8804; 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 [url=http://www.compsci.ca/v2/viewtopic.php?t=9893]zylum's bitwise operators tutorial.

-----------------------------------
perds
Sun Dec 04, 2005 12:46 pm


-----------------------------------
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
Sun Dec 04, 2005 12:47 pm


-----------------------------------
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
Sun Dec 04, 2005 4:37 pm


-----------------------------------
or you know... Ruby :wink: I'm using SHA-1 to encrypt user password information in my rails' application :)
