Guest User

Untitled

a guest
Jun 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int selection;
  4. char select[10];
  5. int i;
  6. int j;
  7. int k;
  8. int ind;
  9. int tmp;
  10. char Matrix[50][50];
  11. //char tmpgets[50];
  12.  
  13. void main(){
  14. menu();
  15. }
  16.  
  17. void input()
  18. {
  19. //clears the array
  20. for(i=0;i<50;i++){
  21. for(j=0;j<50;j++){
  22. Matrix[i][j]='\0';
  23. }
  24. }
  25. char tmp[50] = "\0";
  26. fgets(tmp,50,stdin);
  27. //takes input
  28. int count=0;
  29. //for(i=0;i<50;i++)
  30. while(fgets(tmp,50,stdin))
  31. {
  32. //fgets(tmpgets,50,stdin);
  33. for(j=0;j<50;j++){
  34. if(tmp[j]=='\n'){
  35. tmp[j]='\0';
  36. break;
  37. }
  38. }
  39. if(strlen(tmp)==0){ //wants to stop inputting
  40. break;
  41. } else {
  42. strcpy(Matrix[count],tmp);
  43. count++;
  44. }
  45. /*
  46. for(j=0;j<50;j++){
  47. tmpgets[j]='\0';
  48. }*/
  49. }
  50. menu();
  51. }
  52.  
  53. void encrypt()
  54. {
  55. printf("Enter ind for encryption ");
  56. scanf("%d",&ind);
  57. printf("----------------------------\n");
  58. //makes ind less than 26
  59. if(ind>26){
  60. ind=ind%26;
  61. } else if(ind<0){
  62. printf("ind must be greater than 0");
  63. }
  64. //check if is alphabetical, if so, encrypt, else do nothing
  65. for(i=0; i<50; i++){
  66. for(j=0; j<50; j++){
  67. //if statement, if a-z or A-Z, encrypt, else do nothing.
  68. if(((Matrix[i][j]>=65)&&(Matrix[i][j]<=90))||((Matrix[i][j]>=97)&&(Matrix[i][j]<=122))){
  69. Matrix[i][j]=Matrix[i][j]+ind;
  70. }
  71. }
  72. }
  73. //transpose the matrix
  74. for(i=0;i<50;i++){
  75. for(j=i;j<50;j++){
  76. tmp=Matrix[i][j];
  77. Matrix[i][j]=Matrix[j][i];
  78. Matrix[j][i]=tmp;
  79. }
  80. }
  81. //print the matrix
  82. for(i=0;i<50;i++){
  83. for(j=0;j<50;j++){
  84. printf("%c",Matrix[i][j]);
  85. }
  86. if(strlen(Matrix[i])>0){
  87. printf("\n");
  88. }
  89. }
  90. printf("----------------------------\n");
  91. //go back to menu
  92. menu();
  93. }
  94.  
  95. void decrypt()
  96. {
  97. printf("Enter ind for decryption ");
  98. scanf("%d", &ind);
  99. printf("----------------------------\n");
  100. //makes ind less than 26 always
  101. if(ind>26){
  102. ind=ind%26;
  103. } else if(ind<0){
  104. printf("ind must be greater than 0\n");
  105. }
  106. //check if alphabetical, if so, decrypt, else do nothing
  107. for(i=0; i<50; i++){
  108. for(j=0; j<50; j++){
  109. //if statement, if a-z or A-Z, encrypt, else do nothing.
  110. if(((Matrix[i][j]>=65)&&(Matrix[i][j]<=90))||((Matrix[i][j]>=97)&&(Matrix[i][j]<=122))){
  111. Matrix[i][j]=Matrix[i][j]-ind;
  112. }
  113. }
  114. }
  115. //transpose the matrix
  116. for(i=0;i<50;i++){
  117. for(j=i;j<50;j++){
  118. tmp=Matrix[i][j];
  119. Matrix[i][j]=Matrix[j][i];
  120. Matrix[j][i]=tmp;
  121. }
  122. }
  123. //print the matrix
  124. for(i=0;i<50;i++){
  125. for(j=0;j<50;j++){
  126. printf("%c",Matrix[i][j]);
  127. }
  128. if(strlen(Matrix[i])>0){
  129. printf("\n");
  130. }
  131. }
  132. printf("----------------------------\n");
  133. //go back to menu
  134. menu();
  135. }
  136.  
  137. void menu(){
  138. printf("=-=-=-=-=\n");
  139. printf("MAIN MENU\n");
  140. printf("=-=-=-=-=\n");
  141. printf("1. INPUT TEXT\n");
  142. printf("2. ENCRYPT TEXT\n");
  143. printf("3. DECRYPT TEXT\n");
  144. printf("4. EXIT\n");
  145. printf("Selection: ");
  146. scanf("%d", &selection);
  147. //selection=atoi(select);
  148.  
  149. if(selection == 1){
  150. input();
  151. } else if(selection == 2){
  152. encrypt();
  153. } else if(selection == 3){
  154. decrypt();
  155. } else if(selection == 4){
  156. exit(0);
  157. } else {
  158. printf("input was incorrect\n");
  159. menu();
  160. }
  161. }
Add Comment
Please, Sign In to add comment