Advertisement
WadeRollins2710

[Pascal] Encrypt Message

Feb 9th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.46 KB | None | 0 0
  1. {Encrypt the message                                                      }
  2. {Make a board with m*n size                                               }
  3. {Write the message into the board with VertDir, each box contains a letter}
  4. {Write the message in HorizDir, that is the encrypted message             }
  5. {For example:                                                             }
  6. {Normal Message: "This_is a_test"                                         }
  7. {Board size: 2*7                                                          }
  8. {Board:                                                                   }
  9. {       T i _ s a t s                                                     }
  10. {       h s i _ _ e t                                                     }
  11. {Encrypt Message: "Ti_satshsi__et"                                        }
  12. {See? Nobody will understand}
  13. {This is useful when you need to have a secret conversation with someone  }
  14. {Every one is the conversation need to use this program                   }
  15. {This program can use files to send messages, or you can directly send msg}
  16. {This program will have Graphic User Interface soon                       }
  17. {Enjoy this lame program                                                  }
  18. {You need to make 2 files                         }
  19. Program Sec_Msg;
  20. Uses crt;
  21. Var
  22.    A: Array [1..100,1..100] of char;
  23.    i, j, m, n, k: Integer;
  24.    S, Files, Msg, RecFiles: String;
  25.    Ans: char;
  26.    f: Text;
  27. Procedure Send;
  28.           Begin
  29.                clrscr;
  30.                Write('Input size of board: '); Readln(m, n);
  31.                Write('Input message: '); Readln(S);
  32.                Write('Input file: '); Readln(Files);
  33.                k:=1;
  34.                For i:=1 to m do
  35.                    For j:=1 to n do
  36.                       Begin
  37.                            A[i,j]:=S[k];
  38.                            k:=k+1;
  39.                       End;
  40.                Msg:='';
  41.                For j:=1 to n do
  42.                    For i:=1 to m do
  43.                        Msg:=Msg+A[i,j];
  44.                Assign(f,Files);
  45.                Rewrite(f);
  46.                Writeln(f,Msg);
  47.                Close(f);
  48.           End;
  49. Procedure Receive;
  50.           Begin
  51.                clrscr;
  52.                Write('Input files: '); Readln(files);
  53.                Write('Input files to receive: '); Readln(RecFiles);
  54.                Assign(f,Files);
  55.                Reset(f);
  56.                Readln(f,S);
  57.                Read(f,m,n);
  58.                Close(f);
  59.                k:=1;
  60.                For i:=1 to m do
  61.                    For j:=1 to n do
  62.                        Begin
  63.                             A[i,j]:=S[k];
  64.                             k:=k+1;
  65.                        End;
  66.                Msg:='';
  67.                For j:=1 to n do
  68.                    For i:=1 to m do
  69.                        Msg:=Msg+A[i,j];
  70.                Assign(f,RecFiles);
  71.                Rewrite(f);
  72.                Writeln(f,Msg);
  73.                Close(f);
  74.           End;
  75. Procedure Nhap;
  76.           Begin
  77.                Write('Receive or Send? (R/S) ');
  78.                Ans:=ReadKey;
  79.                While (Upcase(Ans)<>'R') and (Upcase(Ans)<>'S') do
  80.                      Begin
  81.                           Writeln('Press again: ');
  82.                           Ans:=Readkey;
  83.                      End;
  84.                If Upcase(Ans)='R' then
  85.                   Receive;
  86.                If Upcase(Ans)='S' then
  87.                   Send;
  88.           End;
  89. Begin
  90.      clrscr;
  91.      Nhap;
  92. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement