LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Ascii to Char and Char to Ascii conversion (https://www.linuxquestions.org/questions/linux-newbie-8/ascii-to-char-and-char-to-ascii-conversion-923390/)

rakesh.bharad 01-12-2012 01:29 AM

Ascii to Char and Char to Ascii conversion
 
I am completely new to Unix scripting with zero knowledge in it and have the below scenario can you please help me with the complete working script,

First script,

1. Get the string input from the user
2. Convert it to ASCII
3. Increment each character's ASCII value by 2. If the input value contains Y or Z it should be converted to A or B accordingly, same way the string may have special characters and numbers as well and they must be converted accordingly.
4. Form the new word
5. Store this in a file

Eg.

Input : ABCD
Output : CDEF

and this output should be stored at the Value 1 location in a file like,

Value 1 : CDEF
Value 2 : XYX


This file will act as a config file and should be used in another script 2

Script 2 should read these values and before proceeding it should convert it back to original value (i.e. ABCD - should perform the reverse operation).

This is something like encrypting and decryption but its very primary. I am not worried about any security issues by achieving this logic as i am going to implement it on some log files with no value.

I am on solaris 5.10

Thanks
Rakesh

segmentation_fault 01-12-2012 11:31 AM

This looks like Ceasar cipher to me. Are you taking a computer security class? Well, I had this class but I worked on C, not script, where I just incremented the character by "key" (key is an integer). I believe you can do something similar in bash. Google for "Ceasar cipher in bash script".

chrism01 01-12-2012 07:32 PM

As he said, its a Caesar or 'rotation' cipher.
Which lang do you want; personally I'd use Perl.


All times are GMT -5. The time now is 08:55 PM.