Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define LIMIT 100
- char converte(char c , int shift)
- {
- unsigned char d = c ;
- d = d + shift ;
- if (d > 'z') d = ('a' - 1) + (d - 'z') ;
- else if (d < 'a') d = ('z' + 1) - ('a' - d) ;
- return (d) ;
- }
- void desloca(char texto[] , char cifra[] , int shift)
- {
- int i ;
- for (i = 0 ; i < strlen (texto) - 1 ; i++)
- {
- if (isalpha(texto[i]))cifra[i] = converte(texto[i] , shift) ;
- else cifra[i] = texto[i] ;
- }
- cifra[strlen (texto) - 1] = '\0' ;
- }
- void main()
- {
- char txt[LIMIT] , cifra[LIMIT] ;
- int i ;
- printf ("Cifra? ") ;
- fgets (txt , LIMIT , stdin) ;
- for (i = 1 ; i < 26 ; i++)
- {
- desloca (txt , cifra , i) ;
- printf ("com shift + %d : %s\n" , i , cifra) ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment