Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. char Testo[MAX],Cifrato[MAX],c;
  2.     int i=0,K,j=0,delta,resto;
  3.    
  4.     printf("inserisca il numero di K:");
  5.     scanf("%d",&K);
  6.     if(K>26)
  7.     {
  8.         resto=K%26;
  9.         K=K-(26*resto);
  10.     }
  11.     delta=K-26;
  12.     printf("inserisca il testo:");
  13.     while(getchar()!='\n');
  14.    
  15.     while((c=getchar())!='\n')
  16.     {
  17.         Testo[i]=c;
  18.         i++;
  19.     }
  20.     Testo[i]='\0';
  21.     while(Testo[j]!='\0')
  22.     {
  23.         if((Testo[j]>='a' && Testo[j]<='z') || (Testo[j]>='A' && Testo[j]<='Z'))
  24.         {
  25.             if((Testo[j]>=('z'-K) && Testo[j]<='z') || (Testo[j]>=('Z'-K) && Testo[j]<='Z'))
  26.             {
  27.                 Cifrato[j]=Testo[j]+delta;
  28.             }
  29.             else
  30.                 Cifrato[j]=Testo[j]+K;
  31.         }
  32.         j++;
  33.     }
  34.     Cifrato[j+1]='\0';
  35.     printf("%s\n",Cifrato);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement