Post: MD5 Cryptography [C# and Python]
07-01-2011, 03:56 AM #1
schnzrs
Do a barrel roll!
(adsbygoogle = window.adsbygoogle || []).push({}); MD5 Hashing is a one-way form of cryptography. You can encrypt, but you can't decrypt. Every string will have a unique MD5 hash.

For example:
abcd -> e2fc714c4727ee9395f324cd2e7f331f
abdc -> 5e822a0b52c71ce2ff2ecd3aa8ca46fc

The string abcd will always have the same MD5 hash. Pertaining to the string they were generated with, MD5 hashes are static. If you call createMD5Hash("abcd") a million times, it will return the same value every time.

You might not notice this, but this can have many uses. One of the best uses of hash cryptography is to store passwords. A hashed password can be stored in a file, and when a user enters their password, it is hashed and compared to the file. That is secure and simple.

Here are some functions I wrote that simplify generating a MD5 hash:
    //C# MD5 function
using System;
using System.Text;
using System.Security.Cryptography;

string createMD5Hash(string input){
//Create a MD5 object
MD5 md5obj = MD5.Create();
//The ComputeHash method takes an array of bytes as a parameter
byte[] md5hash = md5obj.ComputeHash(Encoding.ASCII.GetBytes(input));
//The array of bytes will be converted to a string
return BitConverter.ToString(md5hash);
}

    
#Python MD5 function
import hashlib

def createMD5Hash(input):
#Create a MD5 object
md5obj = hashlib.md5(input)
#Return the MD5 value by calling the hexdigest method
return md5obj.hexdigest()
07-01-2011, 08:05 PM #2
    def createSHA(input,bit):
if bit == 256:
from hashlib import sha256;
temp=sha256(input);
elif bit == 512:
from hashlib import sha512;
temp=sha512(input);
elif bit == 1:
from hashlib import sha1;
temp=sha1(input);
else:
return "1, 256 or 512 accepted bit types only";
return temp.hexdigest();

createSHA("Pirates",512);
createSHA("Pirates",256);
createSHA("Pirates",1);


Very simple and powerful sha512 function
07-11-2011, 11:14 AM #3
vSaBoTeuR x
< ^ > < ^ >
Originally posted by Relevant View Post
    def createSHA(input,bit):
if bit == 256:
from hashlib import sha256;
temp=sha256(input);
elif bit == 512:
from hashlib import sha512;
temp=sha512(input);
elif bit == 1:
from hashlib import sha1;
temp=sha1(input);
else:
return "1, 256 or 512 accepted bit types only";
return temp.hexdigest();

createSHA("Pirates",512);
createSHA("Pirates",256);
createSHA("Pirates",1);


Very simple and powerful sha512 function


There is no such SHA-algorithm using only 1-bit.
07-11-2011, 12:26 PM #4
Originally posted by xNCK View Post
There is no such SHA-algorithm using only 1-bit.


Well it works :p
08-03-2011, 02:20 AM #5
kiwimoosical
Bounty hunter
SHA-1 has vulnerabilities, never use anything except the SHA-2 versions (384bit / 512bit) as they are the most advanced.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo