473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Simple string hashing

I want to create a simple hash function that can hash strings. Currently I'm
storing passwords as strings in a DB but want to store them as a hash. I
don't need any proper standardised hashing e.g. MD4 or MD5. I also want to
be able to write the function completely using VB Script (therefore no
components etc)

I'm thinking along the lines of converting the string into a number
(probably using the ascii values in some simple formula)
Then divide this by a really large prime number (as large as can fit in a VB
Script variable)
And use the remainder as the hash

This is probably very crude but sufficient for my website. Can anyone give
me any tips on the easiest way to do the above or if it can be improved with
very little extra effort.
Also, what is the largest number that can be stored in a VB script variable,
is it a signed 32 bit number?
And the last question is, how can I find out what the largest prime number
is less than that number? Obviously, I don't need to use a prime number but
it would be better if I did. Thanks in advance
Jul 19 '05 #1
4 8857
Google:
http://p2p.wrox.com/archive/proasp_howto/2002-02/27.asp

Chris.

"Seth" <se**@doesnotexist.com> wrote in message news:rvgDc.96$MI2.70@newsfe6-win...
I want to create a simple hash function that can hash strings. Currently I'm
storing passwords as strings in a DB but want to store them as a hash. I
don't need any proper standardised hashing e.g. MD4 or MD5. I also want to
be able to write the function completely using VB Script (therefore no
components etc)

I'm thinking along the lines of converting the string into a number
(probably using the ascii values in some simple formula)
Then divide this by a really large prime number (as large as can fit in a VB
Script variable)
And use the remainder as the hash

This is probably very crude but sufficient for my website. Can anyone give
me any tips on the easiest way to do the above or if it can be improved with
very little extra effort.
Also, what is the largest number that can be stored in a VB script variable,
is it a signed 32 bit number?
And the last question is, how can I find out what the largest prime number
is less than that number? Obviously, I don't need to use a prime number but
it would be better if I did. Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.710 / Virus Database: 466 - Release Date: 23/06/2004
Jul 19 '05 #2
Thanks for that, works a treat and saved me some time :-)

"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:ui*************@tk2msftngp13.phx.gbl...
Google:
http://p2p.wrox.com/archive/proasp_howto/2002-02/27.asp

Chris.

"Seth" <se**@doesnotexist.com> wrote in message news:rvgDc.96$MI2.70@newsfe6-win... I want to create a simple hash function that can hash strings. Currently I'm storing passwords as strings in a DB but want to store them as a hash. I
don't need any proper standardised hashing e.g. MD4 or MD5. I also want to
be able to write the function completely using VB Script (therefore no
components etc)

I'm thinking along the lines of converting the string into a number
(probably using the ascii values in some simple formula)
Then divide this by a really large prime number (as large as can fit in a VB Script variable)
And use the remainder as the hash

This is probably very crude but sufficient for my website. Can anyone give
me any tips on the easiest way to do the above or if it can be improved with very little extra effort.
Also, what is the largest number that can be stored in a VB script variable, is it a signed 32 bit number?
And the last question is, how can I find out what the largest prime number
is less than that number? Obviously, I don't need to use a prime number but it would be better if I did. Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.710 / Virus Database: 466 - Release Date: 23/06/2004

Jul 19 '05 #3
Seth wrote:
I want to create a simple hash function that can hash strings.
Currently I'm storing passwords as strings in a DB but want to store
them as a hash. I don't need any proper standardised hashing e.g. MD4
or MD5. I also want to be able to write the function completely using
VB Script (therefore no components etc)

Here is a function in VBScript to hash strings in classical ASP:

http://rossm.net/Electronics/Compute...tware/ASP/#MD5

It's fast and efficient from my experience.

In ASP.NET just use the System.Cryptography namespace. There are MD5
functions in it.
I'm thinking along the lines of converting the string into a number
(probably using the ascii values in some simple formula)
Then divide this by a really large prime number (as large as can fit
in a VB Script variable) And use the remainder as the hash

This is probably very crude but sufficient for my website. Can anyone
give me any tips on the easiest way to do the above or if it can be
improved with very little extra effort. Also, what is the largest
number that can be stored in a VB script variable, is it a signed 32
bit number? And the last question is, how can I find out what the
largest prime number is less than that number?

If I knew how to quickly calculate high primes for a 32 bit number... I
wouldn't be telling YOU! I'd be implementing cracks for all the major
algorithms known, and becoming the most (in)famous cryptographer in
history...

:-)

Eric
Jul 19 '05 #4
Thanks for this link, However, I've already implemented the solution Chris
pointed out. It isn't that slow and does the job for me fine.

I also wrote a simple program that would calculate prime numbers. It takes a
number and tells you whether it is prime or not. It also has the option of
if it isn't a prime then it will find the next highest or next lowest prime
number. Knowing the highest prime number for a 32 bit number doesn't let you
crack a one way function any quicker though.

"Eric Gibson" <em*@NOSPAM.NET> wrote in message
news:11*************@bignews2.bellsouth.net...
Seth wrote:
I want to create a simple hash function that can hash strings.
Currently I'm storing passwords as strings in a DB but want to store
them as a hash. I don't need any proper standardised hashing e.g. MD4
or MD5. I also want to be able to write the function completely using
VB Script (therefore no components etc)


Here is a function in VBScript to hash strings in classical ASP:

http://rossm.net/Electronics/Compute...tware/ASP/#MD5

It's fast and efficient from my experience.

In ASP.NET just use the System.Cryptography namespace. There are MD5
functions in it.
I'm thinking along the lines of converting the string into a number
(probably using the ascii values in some simple formula)
Then divide this by a really large prime number (as large as can fit
in a VB Script variable) And use the remainder as the hash

This is probably very crude but sufficient for my website. Can anyone
give me any tips on the easiest way to do the above or if it can be
improved with very little extra effort. Also, what is the largest
number that can be stored in a VB script variable, is it a signed 32
bit number? And the last question is, how can I find out what the
largest prime number is less than that number?

If I knew how to quickly calculate high primes for a 32 bit number... I
wouldn't be telling YOU! I'd be implementing cracks for all the major
algorithms known, and becoming the most (in)famous cryptographer in
history...

:-)

Eric

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Thomas Christmann | last post by:
Hi! First let me apologize for asking this question when there are so many answers to it on Google, but most of them are really contradicting, and making what I want to do very performant is...
14
by: msnews.microsoft.com | last post by:
How can I encrypt and decrypt string?
11
by: Wm. Scott Miller | last post by:
Hello all! We are building applications here and have hashing algorithms to secure secrets (e.g passwords) by producing one way hashes. Now, I've read alot and I've followed most of the advice...
7
by: dlarock | last post by:
I wrote the following to do an MD5 hash. However, I have a problem (I think) with the conversion from the Byte MD5 hash back to string. Watching this through the debugger it appears as if the...
3
by: Dara Durum | last post by:
Hi ! Py2.4, Win32. I need to optimize a program that have a speciality: hash (MD5/SHA1) the file contents (many files). Now I do this in a simple python program, because (what a pity) the...
8
by: Maya | last post by:
Hello all, I'm using MD5 hashing in my application to give unique values to huge list of items my application receives, originally every item's name was difficult to use as an id for this item...
22
by: j1mb0jay | last post by:
I have had to create a simple string encryption program for coursework, I have completed the task and now have to do a write up on how it could be improved at a later date. If you could look...
6
by: buu | last post by:
I'm using getHashCode sub from String object, but sometimes it gives me duplicate values for different strings. Difference is always when there are some numbers in strings. Is there any...
5
by: Oriane | last post by:
Hi, With Asp.net 2.0, when a internet user logs in with a "login authentication form", is the password encrypted when it is sent to the server ? Is is hashed ? Best regards
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.