?
Solved

VFP Encode / Decode Alpha Numeric String

Posted on 2012-09-10
5
Medium Priority
?
1,929 Views
1 Endorsement
Last Modified: 2012-09-10
Hi all. I need a way to encrypt / decrypt an alpha numeric string in vfp 9.

Someone here pointed me toward BITXOR a week or so ago and I am using that in one portion of the program and it works quite well.

However when the string is encoded it results in mostly in odd, unpronounceable characters. I need something that can be spoken, read over the telephone, sort of like a Microsoft key.

I would prefer something that will take a string consisting of both characters and numbers and produce a numeric result.
1
Comment
Question by:formadmirer
  • 3
5 Comments
 
LVL 30

Accepted Solution

by:
Olaf Doschke earned 2000 total points
ID: 38382185
Well, it's not impossible to stay within a set of chars, if you also come from one, eg by CHRTRAN() instead of BITXOR:

#Define ccEncrypt "ghiefmndcyzopqrstuvwxjklab"
lcMessage = "hello"
lcEncrypted = chrtran(lcMessage,'abcdefghijklmnopqrstuvwxyz',ccEncrypt)
lcDecrypted = chrtran(lcEncrypted,ccEncrypt,'abcdefghijklmnopqrstuvwxyz')

You have to keep the ccEncrypt value a secret, of course, as it's you encryption/decryption key. You could apply a password in a may to modify ccEncrypt before usage, so you would have another secret an attacker, or I as the "inventor" of this would need to know to decrypt your encrypted text.

Notice, this does not work with "Hello", before you not also add H to the ccEncrypt. It will remain unchanged, though.

The other thing you can do is use whatever easy or complex encryption, like VFPEncryption FLL and as a final step use Base64 encoding:

cReadable = strconv(cEncrypted,13)
Then on the receiver side
cEncrypted = Strconv(cReadable,14)

It has the disadvantage of being 33% longer, as it encodes 3 ascii bytes in 4 ascii bytes, but readable ones, letters, numbers and a few more 64 readable chars.

Don't be tempted to think this alone really is encryption. It's not, it always generates the same output from the same input, you don't specify any key or password, so it's reversable and if you ever took a look into a mime mail text you can recognize this as base64 format by the typical compostion of the 64 base64 chars.

Bye, Olaf.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 38382210
You can also generate an algorithm for coding and decoding based on the position of the letter and a password.

To maintain within capital alphabets you have to use MOD.

65+MOD(CHRValue,26)

MOD(nDividend, nDivisor)
0
 
LVL 30

Expert Comment

by:Olaf Doschke
ID: 38382430
While MOD puts values into a range of eg 0 to 25, you lose bits you will not be able to reconstruct. As far as I understand formadmirer, the whole process should be reversable to get back to the initial value.

you can do mod(28,26) and get 2, but also Mod(2,26) is 2. If you want to revert from 2 to the original, you can't decide, if the original was 28,2, or any other N*26+2. So you also have to store int(charValue/26). Base64 is already doing that, it spreads 3x8=24 bits into 4x6 bits.

Bye, Olaf.
0
 

Author Closing Comment

by:formadmirer
ID: 38382982
This looks very usable and has some good information - thanks!
0
 
LVL 30

Expert Comment

by:Olaf Doschke
ID: 38383239
Here's one way to incorporate a password into chrtran encryption: Decompose it into it's bits and let each bit decide, wether to switch or not switch tow chars of ccEncrypt before using that for encryption.

You can make a block or stream cipher with it, by encoding lcMessage in blocks of N chars or each char individually.

There are many ideas, maybe you have your own. You could also XOR password chars again, but that will result in unreadable chars or control chars, whcih you want to avoid. My idea is to use the password as control data to shuffle your ccEncrypt translation string. Just make sure each char is in there once only and also make sure every char you want to encrypt is in there.

Bye, Olaf.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question