2. Lex program that implements the Caesar cipher

 

Lex program that implements the Caesar cipher

/* Write a Lex program that implements the Caesar cipher: it replaces every letter 
with the one three letters after in in alphabetical order, wrapping around at Z.
e.g. a is replaced by d, b by e, and so on z by c.  */ 
 
%%
[a-z] {char ch = yytext[0];
ch += 3;
if (ch> 'z') ch -= ('z'+1- 'a');
printf ("%c" ,ch );
}
[A-Z] { char ch = yytext[0] ;
ch += 3;
if (ch> 'Z') ch -= ('Z'+1- 'A');
printf("%c",ch);
}
%%
 
// Output of the above program

Caesar cipher
Caesar cipher

Comments

Popular posts from this blog

Compiler Design

3. Lex program to find the length of the longest word

6. Lex program to count the number of words,small and capital letters, digits and special characters in a C file