Advertisement
Valge

Untitled

Jan 17th, 2022
1,318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.     int x,y,i,j,k,n;
  5.     printf("Enter the size of key matrix: ");
  6.     scanf("%d", &n);
  7.  
  8.     printf("Enter the key matrix: ");
  9.     int a[n][n];
  10.     for(i=0; i<n; i++){
  11.         for(j=0; j<n; j++){
  12.             scanf("%d", &a[n][n]);
  13.         }
  14.     }
  15.     printf("Enter the message to encrypt: ");
  16.     char s;
  17.     scanf("%c", &s);
  18.  
  19.     int temp = (n - sizeof(s)%n)%n;
  20.     for(i=0; i<temp; i++){
  21.         s+='x';
  22.     }
  23.     k=0;
  24.     char ans;
  25.     while(k < sizeof(s)){
  26.         for(i=0; i<n; i++){
  27.             int sum = 0;
  28.             int temp[] = {k};
  29.             for(j=0; j<n; j++){
  30.                 sum += (a[i][j] % 26 * (s[temp++] - 'a')%26)%26;
  31.                 sum = sum % 26;
  32.             }
  33.             ans+=(sum+'a');
  34.         }
  35.         k+=n;
  36.     }
  37.     printf("%c", ans);
  38.  
  39.     return 0;    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement