You can register an iTabCode account to be able to view iTabCode without ads. ( Registration is Free ) Register Now

nayf

New Member
Program Encrypt and decrypt by C++
C++:
#include <iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
int main (){
char small_letter[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char big_letter[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char text[1000],result[1000];
char c;
int i,count=0,k,p;
int function;
printf ("Enter The Text :") ;
c=getchar();
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
{
while(1)
{
if(c == '\n') break;
text[count]=c;
printf("%c",text[count]);
count++;
c=getchar();
}
printf("\n");
printf(" 1:Encipher\n 2:Decipher\nInput 1or2:");
scanf("%d",&function);
if (function == 1)
{
printf("Input the Key:" );
scanf("%d",&k);
if (k>0&&k<=26)
{
for(i=0;i<count;i++)
{
if(text>='A'&&text<='Z')
{
result=big_letter[((text-'A')+k)%26];
}
else if (text>='a'&&text<='z')
{
result=small_letter[((text-'a')+k)%26];
}
else result=text;
printf("%c",result);
}
}
else printf("Please Input 1~26!");
}
else if (function == 2){
for (k=1;k<=26;k++)
{printf("k=%d,",k);
for(i=0;i<count;i++){
if(text>='A'&&text<='Z')
{
p=((text-'A')-k);
while(p<0)p+=26;
result=big_letter[p];
}
else if (text>='a'&&text<='z')
{
p=((text-'a')-k);
while(p<0)p+=26;
result=small_letter[p];
}
else result=text;
printf("%c",result);
}
printf("\n");
}
}
else printf("Formal Error!");
return 0;
}
printf ("plese ınter Englısh letter");
}
 
Top