_____  _____
                   \\\\\\/ ___/___________________
   By Cyneox        \\\\/ /                       _____/__________________________
 ________________    \\/ / http://cyneox.go.ro ______/.'.'.'.'.'.'.'.'.'.'.'.'_'_'_/
 \_____        \__    / /  cyneox@go.ro    _____/.'.'.'.'.'.'.'.'.'.'.'.'.'_'_/
     \__________\__  / /             _____/_'_'_'_'_'_'_'_'_'_'_'_'_'_'_/
                 \_ / /________________/
                  \/____/\\\\\\
                      \\\\\\        Polyalphabetical Ciphering Method
                       ------            [ The Vigenere Cipher ]

   ___
 /   /|       ::::::::::::::::::::        Intro           ::::::::::::::::::::
/___/ |       The polyalphabetical coing method is based on the monoalphabetical
| I | |       coding technique and that great thing about it is that the coding
| n | |       method always changes, of course using special/some criterions.
| t | |
| r | |       For example if you have a text and want to cipher it mono, every
| o | |       letter will be changed/coded into another one. Well if you intend
|   | |       to use this technique every letter group will be coded using a
|   |/        special monoalphabetical key. so that the same letters could be
\___/	      represented by different letters when coded...



  ____
 /   /|       ::::::::::::::::::::: Vigenere and his method :::::::::::::::::::::::::
/___/ |       Blaise de Vigenere was born in 1523. His great cryptographic invention
| V | |       was found in Paris and it was documented as the greatest invention since
| i | |       Julius Caeser. For many years Vigenere's system was called "the
| g | |       indecipherable cipher". this is because, unlike substitution, the same
| e | |       letter was not substituted by the same letter in the cypher. The same
| n | |       letter might be encrypted by many different letters, therefore making it
| e | |       hard to break.
| r | |
| e |/        But since I did not intend to write something about the history of cryp-
\___/         tography or something like that, I'll simply show you an example and
              try to explain that to you.

	      So let us have a look at one example:

	      Our text will be "abba"

	      normal alphabet  :           a b c d e f g h i ....
	      1.cipher-alphabet:           H L W X D J K B ...
	      2.cipher-alphabet:           U L V W A X Y I ...
	      3.cipher-alphabet:           N A R T I M K L ...
	      4.cipher-alphabet:           D Y Z L M H F B ...

	      Our text was "abba". Those letters are in the normal alphabet too.
	      In the first cipher-alphabet "a" will corespond to "H".
	      In the second cipher-alphabet "b" will corespond to "L".
	      In the third one "b" will corespond to "A". (!)
	      In the fourth one "a" will corespong to "D". (!)

	      So the encrypted text will be : "HLAD".
	      Well as you see its quite simple and I hope you all understood it.

	      Now you're probably asking yourself how those cipher-alphabets were
	      created/generated. Well the answer you'll find in the following, so
	      called "Vigenere tableau":

	          A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

	      A   A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
	      B   B C D E F G H I J K L M N O P Q R S T U V W X Y Z A
	      C   C D E F G H I J K L M N O P Q R S T U V W X Y Z A B
	      D   D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
	      E   E F G H I J K L M N O P Q R S T U V W X Y Z A B C D
	      F   F G H I J K L M N O P Q R S T U V W X Y Z A B C D E
	      G   G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
	      H   H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
	      I   I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
	      J   J K L M N O P Q R S T U V W X Y Z A B C D E F G H I
	      K   K L M N O P Q R S T U V W X Y Z A B C D E F G H I J
	      L   L M N O P Q R S T U V W X Y Z A B C D E F G H I J K
	      M   M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
	      N   N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
	      O   O P Q R S T U V W X Y Z A B C D E F G H I J K L M N
	      P   P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
	      Q   Q R S T U V W X Y Z A B C D E F G H I J K L M N O P
	      R   R S T U V W X Y Z A B C D E F G H I J K L M N O P Q
	      S   S T U V W X Y Z A B C D E F G H I J K L M N O P Q R
	      T   T U V W X Y Z A B C D E F G H I J K L M N O P Q R S
	      U   U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
	      V   V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
	      W   W X Y Z A B C D E F G H I J K L M N O P Q R S T U V
	      X   X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
	      Y   Y Z A B C D E F G H I J K L M N O P Q R S T U V W X
	      Z   Z A B C D E F G H I J K L M N O P Q R S T U V W X Y

	                                                  [[ Vigenere tableau ]]


  ____
 /   /|       ::::::::::::::: Learn & Use ( theoretical stuff) :::::::::::::
/___/ |       Like I said before, for this ciphering method you'll need that
| L | |       "alphabetical square" and a KEYWORD, like CYNEOX ;)
| e | |
| a | |       In order to code your text you'll have to write the keyword
| r | |       periodically over your uncrypted text like in the following
| n | |       example:
|   | |
| & | |       Keyword :   C Y N E O X C Y N E O X C Y N E O
|   | |       Text    :   T H I S I S A S I M P L E T E X T
| U | |
| s | |       Ok.So our text will be "ThisIsASimpleText" :-P
| e | |       Now in the next step we'll practice a little bit with our square.
|   |/        Remember: Every letter og your unciphered text will be ciphered
\___/         using the letter of the keyword right over it. In our example:
              "T" with "C", "H" with Y and so on...

	      So if you want to encrypt "T" , you'll have to search the line
	      beginning with "C" :


	      B   B C D E F G H I J K L M N O P Q R S T U V W X Y Z A
	      .........................................................
	      C   C D E F G H I J K L M N O P Q R S T U V W X Y Z A B | <--- there
	      `````````````````````````````````````````````````````````
	      D   D E F G H I J K L M N O P Q R S T U V W X Y Z A B C


	      Then you'll have to find the column beginning with "T":

	                                                      there you go

	                                                           ||
	                                                           ||
	                                                           \/

	                                                           ._.
	                                                           |T|
	                                                           | |
	                                                           |T|
	                  .........................................|U|.............
	                  C   C D E F G H I J K L M N O P Q R S T U|V| W X Y Z A B:
	                  `````````````````````````````````````````|W|`````````````
	                                                           |X|
	      As you see, the column beginning with "T" crosses    |Y|
	      the line beginning with "C" in a certain point.      |Z|
	      The letter coresponding to that point will be our    |A|
	      ciphered letter.In our case "V".                     |B|
	                                                           |C|
	      Well your task is now to encipher the rest of the    |D|
	      text. [Timer activated ... ]                         |E|
	      Already done ??? Ok.Let us compare our results:      |F|
	                                                           |G|
	      Keyword : C Y N E O X C Y N E O X C Y N E O          |H|
	      Text    : T H I S I S A S I M P L E T E X T          |I|
	      Code    : V F V W W P C Q V Q D I G R R B H          |J|
	                                                           |K|
	      Our ciphered text is : VFVW WPCQ VQDI GRRB H         |L|
	      Nice isnt it ?! ;)                                   |M|
	                                                           |N|
	      QUESTION: How do I decode it ???                     |O|
	      ANSWER:   If you have the keyword then search in     |Q|
	                the line beginning with the first letter   |R|
	                of your keyword for the encrypted letter.  |S|
	                In our case: You'll have to search in the  |T|
	                line beginning with "C" for a "V".
			Then go above the "V" and the you'll see
			the letter you'll find will be "T".
			The same thing must be done with the others
			letters etc.


   ___
 /   /|        ::::::::::::::::        Implementations        ::::::::::::::::
/___/ |
| I | |        Of course I tried to write/find some functions, implemenations
| m | |        for this method. I intented to write something in assembler
| p | |        but now I'm quite lazzy so I'll show only C code...
| l | |
| e | |        The main reason why I wrote this, was the idea encoding the
| m | |        the virus body using some poly* techniques.Well its quite difficult
| e | |        to find a really "stealth"/good poly enciphering method. This one
| n | |        has disadvantages too, like every other method.
| t | |        Vigenere didnt know that computer will be developed etc and that
| a | |        they'll use more than 26 signs like he used.So our BIG disadvantage
| t | |        is that we cant code other ASCII signs. This method is only on the
| i | |        alphabet restricted.
| o | |
| n | |
| s | |        ++++++++++++++++++ Implementations ++++++++++++++++++++
|   |/         #define MODULO_ALPHABET 26  // number of signs used in the alphabet
\___/	       #define ENCRYPT(D,X) ('A'+((D-'A')+(X-'A'))% MODULO_ALPHABET
               #define DECRYPT(D,X) ('A'+(MODULO_ALPHABET+(D-'A')-(X-'A'))% MODULO_ALPHABET

               /* encode() simply encodes some data using keyword.
	          The main work is done by ENCRYPT which is a very
		  good macro.I tested it and it really worked.
	       */

               char *encode(char *data,char *keyword)
	       {
	                  int i,keyword_len=strlen(keyword);

			  for(i=0;data[i];i++)
			  {
			      data[i]=ENCRYPT(data[i],keyword[i%keyword_len]);
			  }

			  return data;
	        }

		/* decode(9 decodes data by the method explained
		   before...
		*/

		char *decode(char *data,char *keyword)
		{
		          int i,keyword_len=strlen(keyword);

			  for(i=0;data[i];i++)
			  {
			      data[i]=DECRYPT(data[i],keyword[i%keyword_len]);
			  }

			  return data;
	        }


   ___
 /   /|         ::::::::::::::        Outro           :::::::::::::::
/___/ |         I hope you'll enjoy this *article* while reading it.
| O | |         I'll like to thanks/greet 2 :
| u | |         Caline  -- thank you for beeing such a lovely girlfriend
| t | |         dr3f    -- i hope you'll find your way in the Linux world ;)
| r | |         Rott_En -- thanks budy for everything...for your critical ideas
| o | |         DCA     -- i cant wait for DCA #2
|   | |
|   |/          Cyneox [ http://cyneox.go.ro ]
\___/	     	                [ 07.01.2005 ]