Hi! I've just downloaded offensive fortune-mod cookies. they seem to be encoded . Does anyone know about the encoding algorithm?
Thanks,
On Sun, 21 Sep 2003, Nikhil Joshi wrote:
Hi! I've just downloaded offensive fortune-mod cookies. they seem to be encoded . Does anyone know about the encoding algorithm?
man strfile gave that the alphabets are rotated 13 positions. so i wrote a program , it now works. Can a shell script be written to achieve the same purpose ?
#include <stdio.h> #include <stdlib.h> #include <ctype.h> int main (int argc, char *argv[]) { FILE *in; char ch; if (argc > 1) {
{ in = fopen (argv[1], "r"); if (in == NULL)
{ perror (argv[1]); exit (1); }
}
while ((ch = fgetc (in)) != EOF) { if (isalpha (ch) != 0) { if (isupper (ch) != 0) if ((int) ch > ((int) ('Z') - 13)) ch = (int) ch - 13; else ch = (int) ch + 13;
if (islower (ch) != 0) if ((int) ch > ((int) ('z') - 13)) ch = (int) ch - 13; else ch = (int) ch + 13;
} printf ("%c", ch);
} fclose (in); } else printf ("Usage: %s filename\n", argv[0]); return 0; }
On Sep 21, 2003 at 22:03, Nikhil Joshi wrote:
man strfile gave that the alphabets are rotated 13 positions. so i wrote a program , it now works. Can a shell script be written to achieve the same purpose ?
tr [a-m][n-z][A-M][N-Z] [n-z][a-m][N-Z][A-M]
Untested.
On Sun, 21 Sep 2003, Nikhil Joshi wrote:
man strfile gave that the alphabets are rotated 13 positions.
^^^^^^^^^ letters. an alphabet is a collection of symbols used in a grammar.
The english alphabet has 26 symbols, base64 has 64, the hexadecimal alphabet consists of 16, and utf8 has much more.
so i wrote a program , it now works. Can a shell script be written to achieve the same purpose ?
That aside, what you've seen is called ROT13 encryption. Decryption using the shell is fairly simple using tr:
cat file | tr "a-zA-Z" "n-za-mN-ZA-M" > newfile
of course, this isn't portable across character sets. For that, you'd have to list every single character... but I don't feel like doing that right now.
On Mon, 22 Sep 2003, Philip S Tellis wrote:
cat file | tr "a-zA-Z" "n-za-mN-ZA-M" > newfile
of course, this isn't portable across character sets. For that, you'd have to list every single character... but I don't feel like doing that right now.
man isalpha gave
isalpha() checks for an alphabetic character; in the standard "C" locale, it is equivalent to (isupper(c) || islower(c)). In some locales, there may be additional characters for which isalpha() is true--letters which are neither upper case nor lower case.
i think the locale will take care of the selection of letters automatically.
BTW does anyone know what is a standard "C" locale or for that matter what is a locale ?
On Mon, 22 Sep 2003, Nikhil Joshi wrote:
i think the locale will take care of the selection of letters automatically.
Exactly... which is what we need to prevent. For example, if the locale were fr_FR, then d-f would mean deèéêf - which is not what we want. When we say d-f, we want only def, so we need to explicitly state this, by listing all characters.