PROGRAM Code Breaker

download PROGRAM Code Breaker

of 32

Transcript of PROGRAM Code Breaker

PROGRAM CodeBreaker; {Programmer: Gregory A. Perkins CS 65 Due: 12 December 1996} {This program accepts the name of a coded file, the number of possible key values in the polyalphabetic cypher used, and at least one "known" string within the coded text and decodes the encrypted file and displays it to the user} USES cs65; {Declarations Module} CONST MessMax = 255; CharRange = 95; TopCharCode = 126; KeySize = 10; TYPE Message = ARRAY[1..MessMax] OF CHAR; KeyCode = ARRAY[1..KeySize] OF INTEGER; VAR TestKey, i, Count, NumKeysNeeded, NumKeysFound : INTEGER; CharCycle, MessPointer, NumChecks : INTEGER; Found : BOOLEAN; FileName, SearchString : STRING; InFile : TEXT; Mess, MessAnswer : Message; Key : KeyCode; PROCEDURE Decrypt(Shift : INTEGER; VAR Code : CHAR); VAR NumCode : INTEGER; BEGIN NumCode := ORD(Code) + Shift; IF NumCode > TopCharCode THEN NumCode := NumCode - CharRange; Code := CHR(NumCode); END; BEGIN {program}

{Needed information prompt module} WRITE('Enter the name of the file you would like to read : '); READLN(FileName); WRITE('Enter the number of encryption keys searching for : '); READLN(NumKeysNeeded); WRITE('Enter a known "string" in the encrypted text : '); READLN(SearchString); {Read File Module} RESET(InFile, FileName); i := 0; WHILE NOT EOF(InFile) DO BEGIN i := i + 1; READ(Infile, Mess[i]); END; {while loop}

CLOSE(Infile); {Initialization module} TestKey := 1; {Current "key"/"offset" value used for decryption} NumKeysFound := 0; {Number of "keys" found so far} REPEAT {Status Display Module} WRITE('Testing Key Number : ', TestKey:1,'.'); WRITELN(' Found ', NumKeysFound:1, ' code keys.'); {Decrypt File Module} FOR Count := 1 TO i DO Decrypt(1, Mess[Count]); {Searching module} FOR CharCycle := 1 TO NumKeysNeeded DO BEGIN Found := FALSE; {"Found" is true when there is a possible answer found} MessPointer := 0; REPEAT {compare every char in message to char at CharCycle in SearchString} MessPointer := MessPointer + 1; {point to next char in the message} IF (Mess[MessPointer]) = (SearchString[CharCycle]) THEN BEGIN Found := TRUE; {set Found to true until proved otherwise} FOR NumChecks := 1 TO (((LENGTH(SearchString)) DIV NumKeysNeeded) - 1) DO IF (Mess[MessPointer + (NumKeysNeeded * NumChecks)] SearchString[CharCycle + (NumKeysNeeded * NumChecks)]) THEN Found := FALSE; {set Found to false if string values do not match} END; UNTIL ((Found) OR (MessPointer > i)); IF (MessPointer > i) THEN Found := FALSE; IF (Found) THEN BEGIN

FOR Count := 1 TO i DO IF ((((Count - 1) MOD NumKeysNeeded) + 1) = (((MessPointer - 1) MOD NumKeysNeeded) + 1)) THEN MessAnswer[Count] := Mess[Count]; Key[(((MessPointer - 1) MOD NumKeysNeeded) + 1)] := TestKey; {store current key in appropriate place in array} NumKeysFound := NumKeysFound + 1; {increment number of keys found} END; {if structure} END; {for loop - CharCycle}

TestKey := TestKey + 1;

{Increment current "key"/"offset"}

UNTIL ((NumKeysFound = NumKeysNeeded) OR (TestKey > CharRange)); {Answer Key Display Module} WRITELN; WRITELN('The encryption key is : '); FOR Count := 1 TO NumKeysNeeded DO WRITE(Key[Count]:1, ' '); WRITELN; {Decoded Message Display Module} WRITELN; WRITELN('The message is : '); FOR Count := 1 TO i DO WRITE(MessAnswer[Count]); WRITELN; END. {of program}

3. Mengurutkan Deret Angka

Ada banyak algoritma yang bisa kita gunakan, antara lain Bubble Sort, Insertion Sort, Selection Sort, dan Quick Sort. Phii akan bahas pengurutan menggunakan Bubble Sort karena algoritma ini yang paling simple.

Ok, kita mulai membahas algoritma ini: 1. Siapkan deret angka yang akan diurutkan (beri batasan maksimal jumlah angka yang akan diurutkan) 2. Buat suatu kondisi yang akan menentukan urutan deret angka, denganmembandingkan tiap 2 angka yang posisinya berurutan, misal: jika angka[n] > angka[n-1], maka.. 3. Tukar posisi angka jika memenuhi kondisi di atas tampilkan hasil pengurutan Lihat Source Code#include #include main() {

1. #include 2. #include 3. 4. main() { 5. /* angka[100] menentukan jumlah bilangan yang boleh dimasukan */ 6. int angka[100], tukar, b, n, i; 7. 8. /*bersikan layar keseluruhan */ 9. clrscr(); 10. 11. printf("Masukkan jumlah data ? "); 12. 13. /*input jumlah data di variable n*/ 14. scanf("%d",&n); 15. printf("\n"); 16. 17. for(i=1;i ',j,' jam ',m,' menit ',d,' detik'); end.

4. Program Konversi Waktu di PascalSunday, February 13, 2011 Nah, kali ini saya ingin berbagi ilmu tentang bahasa pemrograman Pascal. ini ada contoh program konversi waktu dengan menggunakan pascal. Pertama masuk dulu ke program pascal terus tulis coding berikut ini atau dengan notepad++ anda bisa langsung save denga extention [dot]Pas. ini source codenya, silahkan di copy aja.. Uses crt; var j,m,d,dm,sisa,sisa1:integer; begin Writeln('======================================='); Writeln('= Program Konversi Waktu ='); Writeln('======================================='); Writeln; Write('Masukkan Jumlah Detik : ');readln(dm); if (dm/3600)>0 then begin j:=dm div 3600; sisa:=dm-(j*3600); end else begin j:=0; sisa:=dm; end; if (sisa/60)>0 then begin m:=sisa div 60; sisa1:=sisa-(m*60); end else begin m:=0;

sisa1:=sisa; end; d:=sisa1; Writeln; Writeln('Hasil => ',j,' jam ',m,' menit ',d,' detik'); Readln; end. Nah, untuk compile dan run-nya udah pada bisa kan... tinggal CTRL+F9 aja..

5.

Program konversi dari detik ke jam C++By nurirwan Program ini mengkonversikan Detik yang jumlah detik yang Anda input akan dikonversikan menjadi Jam, Menit dan Detik Semoga membantu Anda: #include #include int konversi(int n){ int j, m, d ; if (n >= 3600){ j = n/3600; n = n%3600; m = n/60; n = n%60; d = n; } else if (n =60){ j = 0; m = n/60; n = n%60; d = n; } else { j = 0; m = 0; d = n;

} cout