Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MauMan

Looking for a simple string [en|de]cryption API...

This topic is 6482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m looking for a simple string [en|de]cryption API. I want to write a password to a settings file/windows regestry and don''t want to do it clear text :-) It can be windows-specific but it would be better if it was portable.

Share this post


Link to post
Share on other sites
Advertisement
You don''t need decryption function. The standard way to store
crypted password is.

1. Create hash from the password. (Using for example MD5 method)
2. Store this hash in registry or setting file.

When user enters its password create hash using same method
and compare with stored one.

Hashing algorithm guarantee that password cannot be recovered
from hash.

I think you can find algorithm sources somewhere in unix or
even windows public sources.

DLife

Share this post


Link to post
Share on other sites
Yes, hash is the way to go just like DLife explained. You can also do your own hash-function:

  
unsigned int hash(char *s)
{
unsigned int num=0;

for (int i=0;i<strlen(s);i++)
num+=int(s[i])<<i;

return num;
}


Something like that, I just came up with the algo above and I''m not that sure if it''s good. But it works . I suggest using passwords longer than 4 characters, but less than 32.

Share this post


Link to post
Share on other sites
Hashing it won''t guarantee it to be safe, there will always be a way to get it if someone really wants to, it just makes it harder.

But if you want to stop 99.9999% of people cracking it then it should be fine.

Share this post


Link to post
Share on other sites
My apologies; I was not clear on what I wanted to do. You guys are quite right in that it''s straight forward to hash up the password and compare it to the hashed name that the user later enters.

What has me stumped is thatI want to be able to recover the password. I want my program to be able to "remember" a password that the user has entered so [s]he does not have to re-enter it each time.

For example; part of one of my applications involves a webcam so I want to me able to remember the ftp password where the cam is supposed to upload the image. For that matter I''d also like to encrypt the ftp site and username so that only my program knows about it.

If you have any ideas I''d appreciate it!

Thanks!

Share this post


Link to post
Share on other sites
It depends on how secure you want it as to how complicated you want to make it. A very simple method would be to just XOR each character with a know byte to make it unreadable, then XOR again to get back to the original. You can create your own method of this for a simple encryption.

You can also get more complicated encryption systems using a bit more mathematics. The TEA algorithm comes to mind, just do a search in google or something and you should get loads of examples.

Share this post


Link to post
Share on other sites
quote:
Original post by MauMan

My apologies; I was not clear on what I wanted to do. You guys are quite right in that it''s straight forward to hash up the password and compare it to the hashed name that the user later enters.

What has me stumped is thatI want to be able to recover the password. I want my program to be able to "remember" a password that the user has entered so [s]he does not have to re-enter it each time.

For example; part of one of my applications involves a webcam so I want to me able to remember the ftp password where the cam is supposed to upload the image. For that matter I''d also like to encrypt the ftp site and username so that only my program knows about it.

If you have any ideas I''d appreciate it!

Thanks!


Here''s some html/VBScript (similar to VB) for doing it:
  
<html>
<!--
Copyright 2000
This page created by Philip Lettkeman
Last revised: November 3, 2000
-->
<head>
<title>
Simple Encryption
</title>
</head>
<script language="VBScript">
<!--

option explicit

Private Const MIN_ASC = 32 '' Space
Private Const MAX_ASC = 126 '' ~
Dim NUM_ASC
NUM_ASC = MAX_ASC - MIN_ASC + 1


Function NumericPassword(ByVal password)
Dim value
Dim ch
Dim shift1
Dim shift2
Dim i
Dim str_len
''line 25
str_len = Len(password)
For i = 1 To str_len
'' Add the next letter.
ch = Asc(Mid(password, i, 1))
value = value Xor (ch * 2 ^ shift1)
value = value Xor (ch * 2 ^ shift2)

''Change the shift offsets
shift1 = (shift1 + 7) Mod 19
shift2 = (shift2 + 13) Mod 23
Next ''i
NumericPassword = value
End Function

''Encipher the text Line 40
Sub Encipher(ByVal password, ByVal from_text, to_text)
Dim str_len
Dim i
Dim ch

''Initialize the random number generator
Rnd -1
Randomize NumericPassword(password)

''Encipher the string
str_len = Len(from_text)
For i = 1 to str_len
ch = Asc(Mid(from_text, i, 1))

''Ignore nonprinting characters
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch + Int(NUM_ASC * Rnd)
If ch > MAX_ASC Then ch = ch - NUM_ASC
to_text = to_text & Chr(ch)
End If
Next ''i
End Sub

''Decipher the text
Sub Decipher(ByVal password, ByVal from_text, to_text) '' Line 65
Dim str_len
Dim i
Dim ch

''Initialize the random number generator
Rnd -1
Randomize NumericPassword(password)

''Decipher the string.
str_len = Len(from_text)
For i = 1 to str_len
ch = Asc(Mid(from_text, i, 1))

''Ignore non-printing characters.
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch - Int(NUM_ASC * Rnd)
If ch < MIN_ASC Then ch = ch + NUM_ASC
to_text = to_text & Chr(ch)
End If
Next ''i
End Sub

sub cmdEn
Dim cipher_text
''line 90
Encipher document.rand.txtpassword.value, document.rand.txtplain.value, cipher_text
document.rand.txtcipher.value = cipher_text

End sub

sub cmdDe
Dim plain_text

Decipher document.rand.txtpassword.value, document.rand.txtcipher.value, plain_text
document.rand.txtplain.value = plain_text
End sub



-->
</script>
<body bgcolor="#000000">
<div align="center">
<center>

<font color="#ffffff"><B><h1>SIMPLE ENCRYPTION</h1></b></font>
<p>
<font color="#ffffff">This is a simple encryption program. Enter text Plain Text box, enter a password in the Password<br>
box and then press Encipher >>. As long as you keep the password the same, you can clear the <br>
plain text box and press << Decipher and it will place your original text back in the plain text <br>
box. Change the password (even by one letter) and it will scramble the text.
</font>
<p>
<p>
<p>
<hr>
<form name="rand">
<table border="3" width="300">

<tr>
<td align="center">
<font color="#ffffff"><b><h2>PLAIN TEXT</h2></b></font>
</td>
<td>
</td>
<td align="center">
<font color="#ffffff"><b><h2>ENCRYPTED TEXT</h2></b></font>


<tr>
<td align="center"><TEXTAREA ID="txtplain" name="txtplain" rows="15" cols="35" >The quick brown fox jumped over the lazy dog. Now is the time for all good men to come to the aid of the party. :)</textarea></td>
<td align="center">
<table>
<tr>
<td align="center"><font color="#ffffff"><b><h3>PASSWORD:</h3></b></font><input type="text" name="txtpassword" ID="txtpassword" value="secret" size="14"><p></td>
</tr>

<tr>
<td align="center"><input type="button" value="Encipher >>" onclick="cmdEn"></td>
</tr>

<tr>
<td align="center"><input type="button" value="<<Decipher" onclick="cmdDe"></td>
</tr>
</table>
</td>
<td align="center"><TEXTAREA ID="txtcipher" name="txtcipher" rows="15" cols="35" ></textarea></td>
</tr>

</table>
</center>
</div>
</form>
</body>
</html>




BeS
It''s Da BOMB Baby!!!

Share this post


Link to post
Share on other sites
OUCH. This board doesn't like my tables and scripting. Edit my message with the html in the box and then just copy/paste that code into a .htm file in notepad and save it.

HEY MOD or STAFF: Can somebody delete that reply for me?? The reply and topic ID's are as follows:

reply_id=186730&topic_id=36847

Thanks,
Philip


B e S
It's Da BOMB Baby!!!

Edited by - wrenhal on January 11, 2001 1:20:55 PM

Share this post


Link to post
Share on other sites
quote:
Original post by wrenhal

OUCH. This board doesn''t like my tables and scripting. Edit my message with the html in the box and then just copy/paste that code into a .htm file in notepad and save it.

HEY MOD or STAFF: Can somebody delete that reply for me?? The reply and topic ID''s are as follows:

reply_id=186730&topic_id=36847

Thanks,
Philip


B e S
It''s Da BOMB Baby!!!

Edited by - wrenhal on January 11, 2001 1:20:55 PM


Thanks to whomever removed that odd reply. Now that it''s cleared up in here, have you had a chance to try this MauMan?

BeS
It''s Da BOMB Baby!!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Not yet; I got hung up on another aspect of the project and and heading out of town for the weekend. I hope to get back to it on Sunday.

Thanks though; I have several promising leads. I just ned to try them out and see which one works best for me.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!