Author

Topic: SHA Algorithm doubt (Read 252 times)

legendary
Activity: 1750
Merit: 1329
Top Crypto Casino
May 22, 2020, 11:40:04 AM
#2
Sha is commonly use for an algorithm like in hashing. The AND, OR, and NOT those are the logic gates uses these commonly use for computer language

in AND if there is a 0 the value becomes 0. In boolean expression if there is a false it is already false
Example
001
111

Answer
001

Example
H0 - 01100111010001010010001100000001
H1 - 11101111110011011010101110001001
Answer
01100111010001010010001100000001

In OR if there is a true statement it is already true. If there is 1 it becomes 1
Example
011
111
Answer
111

Example
H2 - 10011000101110101101110011111110
H3 - 00010000001100100101010001110110
Answer
10011000101110101101110011111110

In NOT you are going to reverse the particular value. If this is true the value becomes false.
Example
0

Answer
1

Example
H4 - 11000011110100101110000111110000
Answer
 00111100001011010001111000001111

I hope this will help you to enlighten.

Before I create a simple hashing using SHA-256



Code:
 Random r = new Random();
        char[] codes = "abcdefghijklmnopqrstuvwzyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToArray();
        string output;
        void generateKey(int gkey)
        {
            output = null;
            for (int x = 0; x < codes.Length; x++)
            {
              output += codes[r.Next(0, codes.Length)];
            }

            t1bx.Text = output;
        }

        private void B_generate_Click(object sender, RoutedEventArgs e)
        {
            generateKey(10);
        }

        static string ComputeSha256Hash(string rawData)
        {
            // Create a SHA256  
            using (SHA256 sha256Hash = SHA256.Create())
            {
                // ComputeHash - returns byte array  
                byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));

                // Convert byte array to a string  
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < bytes.Length; i++)
                {
                    builder.Append(bytes[i].ToString("x2"));
                }
                return builder.ToString();
            }
        }


        private void B_hash_Click(object sender, RoutedEventArgs e)
        {
            txtbx_hash.Text = ComputeSha256Hash(output);
        }

    


I hope this will help you how to make a sha.
hero member
Activity: 2114
Merit: 603
May 22, 2020, 11:09:40 AM
#1
This is quoted from one of the site which explains SHA algorithm steps.

Quote
The next step is to run a set of functions over the words in a specific order operating off the five variables that were set in step 1. The functions combine AND, OR & NOT operators combined with left shifts.

Hi, I am stuck at one of the step where it says the quoted process.

Step 1 is nothing but creation of five variables, lets say H0 to H4,

For example,

Code:
H0 - 01100111010001010010001100000001
H1 - 11101111110011011010101110001001
H2 - 10011000101110101101110011111110
H3 - 00010000001100100101010001110110
H4 - 11000011110100101110000111110000

Now the above quoted step states that you have to use functions such as AND, OR & NOT to specify the new order in the above code.

I don't understand what they are trying to do here.

How to use those function here and what order to be achieved ?

Jump to: