how can i get the value of ascii character?
ayume
Posts: 19
anybody can help me to get the value of ascii character?
i make some encryption/decryption with Caesar chiper, and i need the value of ascii and then shift it.
i make some encryption/decryption with Caesar chiper, and i need the value of ascii and then shift it.
Comments
abcdefghijklmnopqrstuvwxyz0123456789 <- original order
3456789abcdefghijklmnopqrstuvwxyz012 <- ceasar order with "key" 29 or -7
So the result would be "hkgh7cc7k u"
What you do to cipher, you simply find the index of the actual character you want to cipher in the original order. Then you add the "key" and do a modulo according to the number of characters you have in the original character-set. Then you pick the character from the position you calculated.
I'm not sure, but for finding the index the lookdown instruction could be usefull.
The advantage of using this way is that you can easily modify the character-set. For example adding -,.;: <space> and so on would not change the code.
if i want change 1 (49) become < (60)
i just write like this ?
a:= string ("1")
a:= a + 11
So a:= a+11 ' caesar shift
then (in Basic pseudo code)
if a>126 then a=a -127 ' 127 maps to 0, 128 maps to 1
and then add so space is not included
a = a+33.
and you can combine that into one line
if a>126 then a=(a-127+33)
which simplifies to
if a>126 then a=a-94
You can use a similar technique to limit the character set further, eg leave out all the numbers and {}!@#$%^$ characters
He he, you can even do a proper Caesar cypher and leave out characters that Caesar would not have used, like U and J *grin*
if i want join A and B become AB, what should i write?
a:= A
b:= B
c:= a & b ' not work...
CogOS_IO can easily be replaced by FullDuplexSerial and you have a working program.
This code is generic and you can add any character to the alphabet that you need, which is the advantage of checking against number ranges of valid ascii characters.
Of couse this is a quick hack and if you want to make it fool-proof you have to check the length of the message. It should not be longer than the cipher-buffer. And currently the message should not contain chracters that are not in the alphabet. But both are easy changes.
Simply add it to the end of the previous code.
if i want save the result of chiper/dechiper in a variable, it can't??
You'll need to save the result of the cipher in an array. There's a recent thread with a lot of discussion on storing strings in an array.
Duane
Hope this helps
Here's how I'd join A and B (assuming A and B are characters):
Here's the output:
You should tell us more about your problem. Why do you want to pack several values into a single variable (long) ?
It's common that texts are stored in byte-arrays or byte-buffers - except you deal with unicode. If you want to send it via serial interface, if you want to store it to SD-card .... whatever .... usually these are byte-streams. So, what's the reason to do it different?
i get the data from x-bee, dechiper it, n store to SD card
@MagIO2, your sample codes are helpfull me. i get the idea
@Duane, that's great. i think about bytes and your code is safe me
thank you guys
can you please tell me more about that?
A shift cipher has almost no security from anybody who is even vaguely interested in getting to the information. It's good for an introduction to cryptography, but the 128 bit AES built into the XBees is much better.