Contact Learn C
Copy

Program 217:Scytale Cipher using C

Program 217: What is Scytale Cipher?
 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
 int i,j,k,len,turns,code[100][1000],col;
    char str[1000];
    printf("Enter a Secret Message\n");
    gets(str);
    len=strlen(str);
 printf("Enter number of turns on band\n");
 scanf("%d",&turns);
 k=0;
 //initializing code to zero
 for(i=0;i<len;)
 {
  for(j=0;j<turns;j++)
  {
   code[k][j]=0;
   i++;
  }
  k++;
 }
 k=0;
 //storing messages in code according to turns on band
for(i=0;i<len;)
{
  if(str[i]!=' ')
  {
 for(j=0;j<turns;)
 {
  if(i<=len)
  {
    if(str[i]!=' ')//to avoid spaces in between words
    {
            code[k][j]=(int)str[i];
      i++;   
   j++;  
      }
      else
      {
       i++;
      }

  }
  else
  {
   break;
  }

 }
 k++;
  }
  else
  {
   i++;
  }
}
printf("The encrypted message is\n");
//printing encrypted message which is column wise
col=k;
for(i=0;i<turns;i++)
{
 for(j=0;j<col;j++)
 { 
     if(code[j][i]!=0)
  printf("%c",code[j][i]);
  
 } 
}
printf("\n");
}
Explanation:
Scytale Cipher using C

//Coming Soon...

Output:

Scytale Cipher

Scytale Cipher using C



Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide