#include <stdio.h>
#include <stdlib.h>
#include<time.h>
//Get the maximum length of the program input
#define N 100
#define N2 10
/*
This is mainly the simplest encryption method with conversion order
The rearward movement of all the letters in the order.
But some here after encryption the output of the letter may seem strange,
it is because this is the ASCII code to convert
*/
void encry(char *a,char *b,int length, int password)
{
int i,j;
for(i=0;i < length; i++)
{
b[i] = (a[i] + (password-0));
//printf("%c",b[i]);
}
//printf("\n");
}
/*
This is the inverse of the encryption process,
the encryption process is realized against
After entering through the input will generally be the same as the encrypted data
password decryption can be realized
*/
void decry(char *a,char *b,int length, int password)
{
int i,j;
for(i=0;i < length; i++)
{
b[i] = (a[i] - (password-0));
//printf("%c",b[i]);
}
//printf("\n");
}
/*
Here is mainly to read a string from the keyboard
Here would be judge the read string,
If the specific meaning of the input will perform specific operations,
the following is a list of specific actions:
cls: clear screen
exit: exit
*/
void read(char *b)
{
char a[10];
int back = 0,length,i=0;
scanf("%s",a);
length = strlen(a);
{
if(strcmp(a,"cls")==0)
{
system("cls");
}
else if(strcmp(a,"exit")==0)
{
exit(0);
}
else
{
strcpy(b,a);
}
}
}
/*
The following procedure is to obtain a digital input from the keyboard,
and returned as a return value
Can handle input errors also
In addition to dealing with specific meanings input:
A list of specific meaning input:
cls: clear screen
exit: exit
*/
int readnum()
{
char a[10];
int back = 0,length,i=0;
//Here is the encryption-related.
scanf("%s",a);
length = strlen(a);
for(i=0;i<length;i++)
{
if(isdigit(a[i])==0)
{
break;
}
}
//figure can be identified after this
if(i==length) //number
{
int pow = 10,j;
for(j=length-1;j>=0;j--)
{
if(j==length-1)
{
back = (a[j]-'0');
}
else
{
back += ((a[j]-'0')*pow);
pow = pow *10;
}
//printf("back:::%d ",back);
}
}
//Clear screen operation, mainly the aid of windows operating system calls
else //wrong input
{
if(strcmp(a,"cls")==0)system("cls");
}
return back;
}
void select_sort(int *a,int begin,int end)
{
int i,j,k,max;
for(i=begin+1;i<end;i++)
{
if(a[i] < a[i-1])
{
j=i-1;
max = a[i];
a[i] = a[j];
while(max < a[j])
{
a[j+1] = a[j];
j--;
}
a[j+1] = max;
}
}
}
int main()
{
char a[N] ,b[N],str[]="hEllO,WorLd";
int length,password;
int i,j;
int type;
int sor[N2];
srand((int)time(0)); //Initialize the random number generator
for(i = 0;i < N2;i++)
{
sor[i] = ((rand()%30)+1); //Array initialization
}
printf("Look the number \n");
for(i = 0;i < N2;i++)
{
for(j = 0;j < sor[i];j++)
{
printf("*");
}
printf("\n");
//printf("%d\n",a[i]);
}
//The numbers in the array are sorted in ascending order
select_sort(sor,0,N2);
printf("Look the number after the select sort\n");
for(i = 0;i < N2;i++)
{
for(j = 0;j < sor[i];j++)
{
printf("*");
}
printf("\n");
}
//Here is a simple string handling functions
printf("\nLook this is the origin string\n");
printf("%s\n",str);
printf("we are going to make the char to lower case\n");
for(i=0;i<strlen(str);i++)
{
if(str[i]>'A')
{
if(str[i]<'Z')
{
str[i] = str[i]+'a'-'A';
}
}
}
printf("Look this is the lower case\n");
printf("%s\n",str);
printf("we are going to make the char to upper case\n");
for(i=0;i<strlen(str);i++)
{
if(str[i]>'a')
{
if(str[i]<'z')
{
str[i] = str[i]+'A'-'a';
}
}
}
printf("Look this is the upper case\n");
printf("%s\n",str);
//Here is a simple string copying operation
for(i=0;i<strlen(str);i++)
{
a[i] = str[i];
}
a[i] = '\0';
/*
The following is the main loop
Only input exit to exit
*/
while(1)
{
//scanf("%s",a);
printf("Please input the string \n");
//Here to clean up Enter
fflush(stdin);
read(a);
printf("Please input the password \n");
password = readnum();
/*
Since we do encryption and decryption by ASCII table,
so we base on the position of alphabet on the ASCII to limit
the scope of the password
*/
if(password < -64 || password > 3)
{
printf("-64<password <3 ");
continue;
}
length = strlen(a);
//printf("%s %d\n",a,password);
/*
The following selected for encryption or decryption operation,
and fault-tolerant can handle
*/
printf("please input the type 1 encry 2 decry \n");
type = readnum();
if(type == 1)
{
encry(a,b,length,password);
}
else if(type == 2)
{
//printf("ddddd\n");
decry(a,b,length,password);
}
else
{
printf("please input the right type number the next time \n");
continue;
}
//encry(a,b,length,password);
/*
Output the result of encryption or decryption
Because of the potential of special characters after decryption,
so here is output by one character.
*/
for(i = 0; i < length; i++)
{
printf("%c",b[i]);
}
printf("\n");
}
return 0;
}
#include <stdlib.h>
#include<time.h>
//Get the maximum length of the program input
#define N 100
#define N2 10
/*
This is mainly the simplest encryption method with conversion order
The rearward movement of all the letters in the order.
But some here after encryption the output of the letter may seem strange,
it is because this is the ASCII code to convert
*/
void encry(char *a,char *b,int length, int password)
{
int i,j;
for(i=0;i < length; i++)
{
b[i] = (a[i] + (password-0));
//printf("%c",b[i]);
}
//printf("\n");
}
/*
This is the inverse of the encryption process,
the encryption process is realized against
After entering through the input will generally be the same as the encrypted data
password decryption can be realized
*/
void decry(char *a,char *b,int length, int password)
{
int i,j;
for(i=0;i < length; i++)
{
b[i] = (a[i] - (password-0));
//printf("%c",b[i]);
}
//printf("\n");
}
/*
Here is mainly to read a string from the keyboard
Here would be judge the read string,
If the specific meaning of the input will perform specific operations,
the following is a list of specific actions:
cls: clear screen
exit: exit
*/
void read(char *b)
{
char a[10];
int back = 0,length,i=0;
scanf("%s",a);
length = strlen(a);
{
if(strcmp(a,"cls")==0)
{
system("cls");
}
else if(strcmp(a,"exit")==0)
{
exit(0);
}
else
{
strcpy(b,a);
}
}
}
/*
The following procedure is to obtain a digital input from the keyboard,
and returned as a return value
Can handle input errors also
In addition to dealing with specific meanings input:
A list of specific meaning input:
cls: clear screen
exit: exit
*/
int readnum()
{
char a[10];
int back = 0,length,i=0;
//Here is the encryption-related.
scanf("%s",a);
length = strlen(a);
for(i=0;i<length;i++)
{
if(isdigit(a[i])==0)
{
break;
}
}
//figure can be identified after this
if(i==length) //number
{
int pow = 10,j;
for(j=length-1;j>=0;j--)
{
if(j==length-1)
{
back = (a[j]-'0');
}
else
{
back += ((a[j]-'0')*pow);
pow = pow *10;
}
//printf("back:::%d ",back);
}
}
//Clear screen operation, mainly the aid of windows operating system calls
else //wrong input
{
if(strcmp(a,"cls")==0)system("cls");
}
return back;
}
void select_sort(int *a,int begin,int end)
{
int i,j,k,max;
for(i=begin+1;i<end;i++)
{
if(a[i] < a[i-1])
{
j=i-1;
max = a[i];
a[i] = a[j];
while(max < a[j])
{
a[j+1] = a[j];
j--;
}
a[j+1] = max;
}
}
}
int main()
{
char a[N] ,b[N],str[]="hEllO,WorLd";
int length,password;
int i,j;
int type;
int sor[N2];
srand((int)time(0)); //Initialize the random number generator
for(i = 0;i < N2;i++)
{
sor[i] = ((rand()%30)+1); //Array initialization
}
printf("Look the number \n");
for(i = 0;i < N2;i++)
{
for(j = 0;j < sor[i];j++)
{
printf("*");
}
printf("\n");
//printf("%d\n",a[i]);
}
//The numbers in the array are sorted in ascending order
select_sort(sor,0,N2);
printf("Look the number after the select sort\n");
for(i = 0;i < N2;i++)
{
for(j = 0;j < sor[i];j++)
{
printf("*");
}
printf("\n");
}
//Here is a simple string handling functions
printf("\nLook this is the origin string\n");
printf("%s\n",str);
printf("we are going to make the char to lower case\n");
for(i=0;i<strlen(str);i++)
{
if(str[i]>'A')
{
if(str[i]<'Z')
{
str[i] = str[i]+'a'-'A';
}
}
}
printf("Look this is the lower case\n");
printf("%s\n",str);
printf("we are going to make the char to upper case\n");
for(i=0;i<strlen(str);i++)
{
if(str[i]>'a')
{
if(str[i]<'z')
{
str[i] = str[i]+'A'-'a';
}
}
}
printf("Look this is the upper case\n");
printf("%s\n",str);
//Here is a simple string copying operation
for(i=0;i<strlen(str);i++)
{
a[i] = str[i];
}
a[i] = '\0';
/*
The following is the main loop
Only input exit to exit
*/
while(1)
{
//scanf("%s",a);
printf("Please input the string \n");
//Here to clean up Enter
fflush(stdin);
read(a);
printf("Please input the password \n");
password = readnum();
/*
Since we do encryption and decryption by ASCII table,
so we base on the position of alphabet on the ASCII to limit
the scope of the password
*/
if(password < -64 || password > 3)
{
printf("-64<password <3 ");
continue;
}
length = strlen(a);
//printf("%s %d\n",a,password);
/*
The following selected for encryption or decryption operation,
and fault-tolerant can handle
*/
printf("please input the type 1 encry 2 decry \n");
type = readnum();
if(type == 1)
{
encry(a,b,length,password);
}
else if(type == 2)
{
//printf("ddddd\n");
decry(a,b,length,password);
}
else
{
printf("please input the right type number the next time \n");
continue;
}
//encry(a,b,length,password);
/*
Output the result of encryption or decryption
Because of the potential of special characters after decryption,
so here is output by one character.
*/
for(i = 0; i < length; i++)
{
printf("%c",b[i]);
}
printf("\n");
}
return 0;
}