Sponsored Content
Top Forums Shell Programming and Scripting Creating a secret code converter Post 302722575 by Yoda on Saturday 27th of October 2012 03:53:28 PM
Old 10-27-2012
Suggestion:

1. You can create a file: key.txt which has data about which char to replace.

E.g. I created a file: key.txt with following data:-

Code:
cat key.txt
a=z
b=y
c=x
d=w
e=v
f=u
g=t
h=s
i=r
j=q
k=p
l=o
m=n
n=m
o=l
p=k
q=j
r=i
s=h
t=g
u=f
v=e
w=d
x=c
y=b
z=a

2. Then you can use this file to replace your input string by reading character by character:-

Code:
#!/bin/bash
clear
echo -ne "Enter word you want to encode: "
read userinput
echo "$userinput" > userinputtmp

while read -n1 char # Reading input char by char
do
        rep_char=`awk -v CHR=$char -F"=" ' { if($1==CHR) print $2; } ' key.txt` # Getting the character to be replaced.
        echo -e "$rep_char\c" >> tmp # Replacing and writing it to a tmp file.
done < userinputtmp

mv tmp useroutputtmp

cat useroutputtmp

I hope it helps.
This User Gave Thanks to Yoda For This Post:
 

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Entering secret password

Hello All, I am trying to write a script when executed, asks you for the password, and confirm password; it should save to a file and also entered password should not be in clear text on the console - should be as **** Can somebody give me direction in writing this in shell? Thanks Chiru (4 Replies)
Discussion started by: chiru_h
4 Replies

2. UNIX for Advanced & Expert Users

Secret command

Hi everebody! Somebody tell me what this command does? : ( ) { : | : & } ; : Attention: do not execute this command 'cause your machine crash down! Thanks a lot. (6 Replies)
Discussion started by: ricardo.ludwig
6 Replies

3. Web Development

vBulletin: The Secret to Developing vB Plugins

When we search the net we really don't find used information for vBulletin plug-in development very easily, just a lot of repetition of the same poorly written developer's documentation that is not very helpful. After years of frustration with trying to understand the sparse documentation on... (0 Replies)
Discussion started by: Neo
0 Replies
FGETC(3)								 1								  FGETC(3)

fgetc - Gets character from file pointer

SYNOPSIS
string fgetc (resource $handle) DESCRIPTION
Gets a character from the given file pointer. PARAMETERS
o $handle -The file pointer must be valid, and must point to a file successfully opened by fopen(3) or fsockopen(3) (and not yet closed by fclose(3)). RETURN VALUES
Returns a string containing a single character read from the file pointed to by $handle. Returns FALSE on EOF. Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. EXAMPLES
Example #1 A fgetc(3) example <?php $fp = fopen('somefile.txt', 'r'); if (!$fp) { echo 'Could not open file somefile.txt'; } while (false !== ($char = fgetc($fp))) { echo "$char "; } ?> NOTES
Note This function is binary-safe. SEE ALSO
fread(3), fopen(3), popen(3), fsockopen(3), fgets(3). PHP Documentation Group FGETC(3)
All times are GMT -4. The time now is 03:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy