You are on page 1of 2

1/20/2014

C Code Of Vernam Cipher - C And C++ | Dream.In.Code

view source print?


0 1# i n c l u d e< s t d i o . h > 0 2# i n c l u d e< c o n i o . h > 0 3# i n c l u d e< s t d l i b . h > 0 4 c h a ra [ 2 7 ] = 0 5 { ' 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 ' } ; 0 6i n tr n d [ 2 7 ] ; 0 7i n tc o d e [ 1 0 ] , i , j ; 0 8c h a ri n [ 1 0 ] , t e m p , o u t [ 1 0 ] ; 0 9 1 0i n tm a i n( v o i d ) 1 1{ 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 9 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 }
1/2

/ / i n p u t c l r s c r ( ) ; p r i n t f ( " P l e a s ee n t e rt h ei n p u t " ) ; f o r ( i = 0 ; i < 1 0 ; i + + ) { s c a n f ( " % c " , & t e m p ) ; i f( t e m p= =3 2| |t e m p= = ' \ 0 ' ) { c o n t i n u e ; } e l s e { i n [ i ] = t e m p ; } } / / r a n d o mg e n r a t i o n&p r e s e r v i n gi tf o r( i = 0 ; i < 1 0 ; i + + ) {

f o r ( j = 0 ; j < 2 7 ; j + + ) { i f( i n [ i ] = = a [ j ] ) { r n d [ j ] =r a n d ( ) % 1 0 0 ; } } } f o r( i = 0 ; i < 1 0 ; i + + ) { f o r ( j = 0 ; j < 2 7 ; j + + ) { i f( r n d [ j ] ! = 0 ) { c o d e [ i ] =( i n [ i ]+r n d [ j ] ) % 2 6 ; }

3 8/ / V e r n a mo p e r a t i o n -

http://www.dreamincode.net/forums/topic/122540-c-code-of-vernam-cipher/

1/20/2014

C Code Of Vernam Cipher - C And C++ | Dream.In.Code

4 8 5 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 6 1 6 2 6 3 6 4 6 5 6 6

} f o r( i = 0 ; i < 1 0 ; i + + ) { f o r ( j = 0 ; j < 2 7 ; j + + ) { i f( c o d e [ i ] = = j ) { o u t [ i ] = a [ j ] ; } } } f o r ( i = 0 ; i < 1 0 ; i + + ) { p r i n t f ( " % c " , o u t [ i ] ) ; }

4 9 / / A c t u a lT e x tc o n v e r s i o nf r o mc o d e-

6 0 / / O U T -

6 7g e t c h ( ) ; 6 8r e t u r n0 ; 6 9}

http://www.dreamincode.net/forums/topic/122540-c-code-of-vernam-cipher/

2/2

You might also like