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

7. Lex specification program that generates a C program which takes a string “abcd” and prints the pattern

10. Program in YACC to recognize the string „abbb^n, „ab^n „a^n of the langauge (a^n b^n , n>=1)