Lex Program that implements 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 cipher_char = yytext[0];
cipher_char += 3;
if (cipher_char> 'z') cipher_char -= ('z'+1- 'a');
printf ("%c" ,cipher_char );
}
[A-Z] { char cipher_char = yytext[0] ;
cipher_char += 3;
if (cipher_char> 'Z') cipher_char -= ('Z'+1- 'A');
printf("%c",cipher_char);
}
%%

/*Output of this program*/


1 comment:

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...