login about faq

In examples (http://www.example-code.com/foxpro/crypt2_arc4.asp) there is example for ARC4 encryption:

loCrypt.CryptAlgorithm = "arc4"
loCrypt.EncodingMode = "hex"
lcKeyHex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"
lcEncStr = loCrypt.EncryptStringENC("The quick brown fox jumps over the lazy dog.")
? lcEncStr
lcDecStr = loCrypt.DecryptStringENC(lcEncStr)
? lcDecStr

and this code works perfectly. But when I change encoding type from "hex" to "ascii"

loCrypt.EncodingMode = "ascii"

then EncryptStringENC method does not return all characters (it should be the same number as in encrypted text). It is evident that characters with ASCII value higher than 127 are deleted.

Also DecryptStringENC does not accept encrypted char string that contains binary chars (chars with ASCII > 127).

Is this by design or is this a bug? How I can get binary coded string with encoded text? And how I can put binary string with encoded text to DecryptStringENC method? Normally ARC4 encryption is symmetrical and providing this code

loCrypt.EncryptStringENC(loCrypt.EncryptStringENC("Text to encrypt"))  && Yes, there is EncryptStringENC used twice

should return the original "Text to encrypt" string.

The only method I have found is recode string to hexa, use "hex" EncodingMode, use "hex" CharSet and encode again from hexa to char string. So my universal (encoding and/or decoding) function looks like:

FUNCTION aRC4(input_text, secure_key)
LOCAL lcTxt, lcOut
loCrypt.CryptAlgorithm = "arc4"
loCrypt.EncodingMode = "hex"    && Output will be in hexa
loCrypt.charset = "hex"     && Input will be in hexa
lcTxt=loCrypt.EncodeString(input_text,'ansi','hex') && recode text to hexa code
lcOut = loCrypt.EncryptStringENC(lcTxt)
lcOut = loCrypt.DecodeString(lcOut,'ansi','hex')    && Recode hexa output to binary text

But this looks little bit complicated.

Thanks for your help.


asked Apr 16 '16 at 17:25

mydlo's gravatar image


It looks the original question was too complicated as nobody answered it yet.

So short clear question: Should the ASCII encoding (EncodingMode="ascii") return characters from the whole (extended ASCII) range (chars with ASCII codes 0 to 255) or only characters from the pure US ASCII (chars with ASCII codes from 0 to 127)?



answered Apr 21 '16 at 01:15

mydlo's gravatar image


Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Apr 16 '16 at 17:25

Seen: 1,366 times

Last updated: Apr 21 '16 at 01:15

powered by OSQA