Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int selection;
- char select[10];
- int i;
- int j;
- int k;
- int ind;
- int tmp;
- char Matrix[50][50];
- //char tmpgets[50];
- void main(){
- menu();
- }
- void input()
- {
- //clears the array
- for(i=0;i<50;i++){
- for(j=0;j<50;j++){
- Matrix[i][j]='\0';
- }
- }
- char tmp[50] = "\0";
- fgets(tmp,50,stdin);
- //takes input
- int count=0;
- //for(i=0;i<50;i++)
- while(fgets(tmp,50,stdin))
- {
- //fgets(tmpgets,50,stdin);
- for(j=0;j<50;j++){
- if(tmp[j]=='\n'){
- tmp[j]='\0';
- break;
- }
- }
- if(strlen(tmp)==0){ //wants to stop inputting
- break;
- } else {
- strcpy(Matrix[count],tmp);
- count++;
- }
- /*
- for(j=0;j<50;j++){
- tmpgets[j]='\0';
- }*/
- }
- menu();
- }
- void encrypt()
- {
- printf("Enter ind for encryption ");
- scanf("%d",&ind);
- printf("----------------------------\n");
- //makes ind less than 26
- if(ind>26){
- ind=ind%26;
- } else if(ind<0){
- printf("ind must be greater than 0");
- }
- //check if is alphabetical, if so, encrypt, else do nothing
- for(i=0; i<50; i++){
- for(j=0; j<50; j++){
- //if statement, if a-z or A-Z, encrypt, else do nothing.
- if(((Matrix[i][j]>=65)&&(Matrix[i][j]<=90))||((Matrix[i][j]>=97)&&(Matrix[i][j]<=122))){
- Matrix[i][j]=Matrix[i][j]+ind;
- }
- }
- }
- //transpose the matrix
- for(i=0;i<50;i++){
- for(j=i;j<50;j++){
- tmp=Matrix[i][j];
- Matrix[i][j]=Matrix[j][i];
- Matrix[j][i]=tmp;
- }
- }
- //print the matrix
- for(i=0;i<50;i++){
- for(j=0;j<50;j++){
- printf("%c",Matrix[i][j]);
- }
- if(strlen(Matrix[i])>0){
- printf("\n");
- }
- }
- printf("----------------------------\n");
- //go back to menu
- menu();
- }
- void decrypt()
- {
- printf("Enter ind for decryption ");
- scanf("%d", &ind);
- printf("----------------------------\n");
- //makes ind less than 26 always
- if(ind>26){
- ind=ind%26;
- } else if(ind<0){
- printf("ind must be greater than 0\n");
- }
- //check if alphabetical, if so, decrypt, else do nothing
- for(i=0; i<50; i++){
- for(j=0; j<50; j++){
- //if statement, if a-z or A-Z, encrypt, else do nothing.
- if(((Matrix[i][j]>=65)&&(Matrix[i][j]<=90))||((Matrix[i][j]>=97)&&(Matrix[i][j]<=122))){
- Matrix[i][j]=Matrix[i][j]-ind;
- }
- }
- }
- //transpose the matrix
- for(i=0;i<50;i++){
- for(j=i;j<50;j++){
- tmp=Matrix[i][j];
- Matrix[i][j]=Matrix[j][i];
- Matrix[j][i]=tmp;
- }
- }
- //print the matrix
- for(i=0;i<50;i++){
- for(j=0;j<50;j++){
- printf("%c",Matrix[i][j]);
- }
- if(strlen(Matrix[i])>0){
- printf("\n");
- }
- }
- printf("----------------------------\n");
- //go back to menu
- menu();
- }
- void menu(){
- printf("=-=-=-=-=\n");
- printf("MAIN MENU\n");
- printf("=-=-=-=-=\n");
- printf("1. INPUT TEXT\n");
- printf("2. ENCRYPT TEXT\n");
- printf("3. DECRYPT TEXT\n");
- printf("4. EXIT\n");
- printf("Selection: ");
- scanf("%d", &selection);
- //selection=atoi(select);
- if(selection == 1){
- input();
- } else if(selection == 2){
- encrypt();
- } else if(selection == 3){
- decrypt();
- } else if(selection == 4){
- exit(0);
- } else {
- printf("input was incorrect\n");
- menu();
- }
- }
Add Comment
Please, Sign In to add comment