Author Topic: Decoding and Encoding text messages  (Read 5691 times)

0 Members and 1 Guest are viewing this topic.

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Decoding and Encoding text messages
« on: May 24, 2007 »
Hello guys - sorry it's been a while - I should be back in full flow soon - been a hectic few months since my daughter was born!
Im getting married on Monday as well so all the build up to that is near completion!

BUT Im working on something serious for work - a password generator . . .

basically all it needs to do is offset characters i.e.

"andy woz ere" becomes "bmez xpa fsf" - but you should be able to change the offset value (in this case just one!)

any ideas? in freebasic?

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Decoding and Encoding text messages
« Reply #1 on: May 24, 2007 »
that should be quite easy drew!

the way i would do it is to create an string array that holds all the letters in the alphabet.

then something like this for offseting the password

Code: [Select]

dim as string encrypted_password(size of original password)

for x=0 to size of original password
        encrypted_password(x) = alphabet_array((asc(original_password(x))-64)+offset)
next

something like that might work remeber the - 64 part is just based on if you youse big letters you should extend the array to hold big and small letters but inbetween the big and small letters put 6 spaces.

http://www.neurophys.wisc.edu/comp/docs/ascii.html
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Decoding and Encoding text messages
« Reply #2 on: May 24, 2007 »
Thanks Nino!

The ascii table is handy too!!

Must get back into programming in FreeBasic again!!!
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Decoding and Encoding text messages
« Reply #3 on: May 24, 2007 »
Password generator is a nice idea :)

And congratulations on your forthcoming wedding!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: Decoding and Encoding text messages
« Reply #4 on: May 26, 2007 »
This might not be much help, but I made this a while back... just for fun. ;)

By the way, congratulations. :D

Code: [Select]
Declare Sub Encrypt_Decrypt_String( Byref Test As String, Byref Password As String )

Dim As String Test

Test = "IMPORTANT: "
Test+="READ CAREFULLY: This Microsoft End-User License Agreement (EULA) is a "
Test+="legal agreement between you (either an individual or a single entity) and "
Test+="Microsoft Corporation for the Microsoft software product identified above, "
Test+="which includes computer software and may include associated media, printed "
Test+="materials, and online or electronic documentation (SOFTWARE PRODUCT). "
Test+="By installing, copying, or otherwise using the SOFTWARE PRODUCT, you agree "
Test+="to be bound by the terms of this EULA. If you do not agree to the terms of "
Test+="this EULA, do not install or use the SOFTWARE PRODUCT; you may, however, "
Test+="return it to your place of purchase for a full refund."

Test+="Software PRODUCT LICENSE"
Test+="The SOFTWARE PRODUCT is protected by copyright laws and international "
Test+="copyright treaties, as well as other intellectual property laws and "
Test+="treaties. The SOFTWARE PRODUCT is licensed, not sold.  NOTE:  The terms of "
Test+="a printed, paper EULA which may accompany the SOFTWARE PRODUCT supersede "
Test+="the terms of any on-screen EULA found within the SOFTWARE PRODUCT. "


'dim as integer fnum = freefile
'open "readme.txt" for binary as #fnum
'    Do while eof(fnum) = 0
'        Dim As String rec
'        input #fnum, rec
'        Test+=rec
'    loop
'close #fnum


Print Test
sleep 1000,1
cls
Dim As String Password, encrypt, decrypt
Input "Enter Password.", Password
Encrypt_Decrypt_String( Test, Password )

cls
Print Test
sleep 1000, 1

cls
Input "Enter Password.", Password
Encrypt_Decrypt_String( Test, Password )
Print Test
sleep




Sub Encrypt_Decrypt_String( Byref Test As String, Byref Password As String )
    Dim As String Encrypt
    Dim As Integer ti, nt, tval, plen, slen
    slen = len(Test)
    plen = len(password)
   
    For i as integer = 1 to slen
        tval = ASC(Mid(Test, i))
        ti = (ti MOD plen) + 1
        nt = ((ti+(i\plen)) MOD plen) + 1
        tval XOR = (ASC(Mid(Password, ti)) * (plen + ti) + ASC(Mid(Password, nt)))
        encrypt+=Chr(tVal)
    Next
    Test = Encrypt
End Sub
The Dr. is INsane!!!

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Decoding and Encoding text messages
« Reply #5 on: May 28, 2007 »
Have some Karma for that Dr_D.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Decoding and Encoding text messages
« Reply #6 on: May 28, 2007 »
never even noticed this very cool Dr_D!
Challenge Trophies Won:

Offline psygate

  • Completly Insane.
  • Atari ST
  • ***
  • Posts: 173
  • Karma: 7
  • That boy needs therapy.
    • View Profile
Re: Decoding and Encoding text messages
« Reply #7 on: June 03, 2007 »
Did I get that right, that you'd like to do something like the Caesar-Chiffre??
He who controlles the minds commands the many.
He who commands the many, conqueres the minds.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Decoding and Encoding text messages
« Reply #8 on: June 04, 2007 »
That's exactly it.

Jim
Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Decoding and Encoding text messages
« Reply #9 on: June 04, 2007 »
This is in excess of what you need, but I think its worth a mention as we are on this topic :)

The safest way to secure a password would be to use a oneway hashing algorithm like md5 or shl1

You then save the hashed password in the database, then everytime the user enters a password, it gets hashed and compared to the hashed password in the database. This has the added bonus of keeping the password hidden from system admins who have access to the database.

Because there are a lot of sites out there that store a massive database of hashed words, so you simply give it the hash and it returns the cleartext if its in the database, it would be wise to secure it further with a salt. The way this works is that each user will have an additional variable which should contain a random sequence of characters, thats associated with the username. That gets added to the end of the hashed password and send through the hashing algorithm a second time.

i.e. if I had a function called md5( String ) then each user has a record :-

Record User
  Field Name : String
  Field Salt : String
  Field hash : String
End Record

then when I create a new User, I would also assign a random string to the Salt field.

  User.Name = UserName
  User.Salt = randomString( length = 6 )

Finally, when I create the hash field I would do: -

  User.hash = md5( md5( Password ) + User.Salt )

where the + denotes a concatination of the hased Password and Salt.
You would use the same hashing process on the provided Password everytime the user tries to login.

This is becoming the norm for online forums/login systems too.
« Last Edit: June 04, 2007 by Tetra »
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Decoding and Encoding text messages
« Reply #10 on: June 04, 2007 »
Crikey - thanks guys for all the help! Im definately back now and hopefully with some new bits n bobs soon!!!

thanks for the messages guys - appreciate it!

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Decoding and Encoding text messages
« Reply #11 on: June 05, 2007 »
Done it . . . slightly different to what i originally thought but hey ho it works!

this is exactly what i wanted - thanks to everybody who looked on and helped!

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Decoding and Encoding text messages
« Reply #12 on: June 05, 2007 »
heh thats kool k+
Challenge Trophies Won: