Converting a String to a unique integer

I'm writing a program where I need to convert a password - e.g "hello" to an integer value - e.g 4999 - but so the same letters in a different order - e.g lehol would equal a different value.
LVL 1
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I think something like this would make it.

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{\$R *.DFM}
Uses Math;

function CalculateValue( Letter : Char; Position : Integer ) : Integer;
Var
i : Integer;
begin
i := Round( Power( 10, Position ));
Result := Ord( Letter ) * i;
end;

procedure TForm1.Button1Click(Sender: TObject);
Var
n, i    : LongInt;
begin
i := 0;
for n := 1 to Length( Edit1.Text ) do
i := i + CalculateValue( Edit1.Text[n], n );
Label1.Caption := IntToStr( i );

end;

end.

No?

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
function CalculateValue( Letter : Char; Position : Integer ) : Integer;
Var
i : Integer;
begin
i := Round( Power( 2, Position ));
Result := Ord( Letter ) * i;
end;

Would be better. Not to run out of integer too fast.

0
Commented:
hi rarigo,
and otherwise?
meikl
0
Commented:
What do you need that for?

Depending on your needs (digital signatures) you can use CRC32.

Alex
0
Commented:
Hi Kretzschmar,

Sorry. I didn't get you.

Reginaldo
0
Commented:
Reginaldo
meikl likes to see the way back from the integer, you build,
to e.g. the original password (hello)
Indi
0
Commented:
If you don't need the integer as one coherent number you could simply recast the string as a pchar

GL
Mike
0
Commented:
If you don't need the integer as one coherent number you could simply recast the string as a pchar

GL
Mike
0
Commented:
Hi indi,

I don't think you need that. In fact that's no recomended to "decrypt" a password.

Reginaldo
0
Commented:
Hi,

I think Bogieman want to decrypt the integer to the string instead of just encrypt. If it's the case, I would like to know about the max length of the string, the characters ( I mean u use case sensitive ? You only use alphabet ? etc. )

LexZEUS
0
Commented:
If you use Delphi 4, you can use Int64 if you need long key value :

function Power(a, b: integer): Int64;
var
i: integer;
begin
Result:= 1;
for i:= 1 to b do
Result:= Result * a;
end;

var
i: integer;
begin
Result:= 0;
for i:= 1 to Length(Password) do
Result:= Result + Power(255, i-1);
end;

Motaz
0
Commented:
Hi guys,

I just stumbled across a function I never seen before which could just do what bogieman_ needs. have a look at

LHashValOfName

(D5, don't know if lower versions have this one) and

LHashValOfNameSys

(WinAPI).

Ciao, Mike
0
Commented:
It would help if the user said what he wants with a little more precision and details.
0
Commented:
Ah Alex, there's an open question for you at:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10216665

Ciao, Mike

PS: bogieman_ is well known being someone who asks questions with very low points and does seldom reply :-/
0
Author Commented:
Very well done! I changed it to a function where you just input a string, but that was helpful anyway
0
Commented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp

Thank you,
Moondancer
Moderator @ Experts Exchange
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.