Article · October 008 citations reads 5,930 authors


Download 77.34 Kb.
Pdf ko'rish
bet3/9
Sana08.11.2023
Hajmi77.34 Kb.
#1757503
1   2   3   4   5   6   7   8   9
Bog'liq
The book cipher algorithm (1) (1)

Listing One
// bkadd
#include
#include
#include
#include
#define MAX_WORD_LEN 100
int main(int argc, char *argv[])
{
FILE *fp_cod, *fp_book;
int ch, charno;
char word[MAX_WORD_LEN];
int fromstart = 1;
int wlen = 0;
// Argument processing
char code[_MAX_PATH], book[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
if (argc != 3 && argc != 4) goto error1;
_splitpath(argv[1], drive, dir, fname, ext );
if (strlen(ext) == 0) strcpy(ext, "cod");
_makepath(code, drive, dir, fname, ext);
_splitpath(argv[2], drive, dir, fname, ext );
if (strlen(ext) == 0) strcpy(ext, "txt");
_makepath(book, drive, dir, fname, ext);
if (argc == 3 ||(sscanf(argv[3], "%d", &charno) != 1)
|| (charno == 0)) charno=1;
if (charno < 0) { fromstart = 0; charno = -charno; }
// File opening
if ((fp_cod = fopen(code, "a")) == NULL) goto error2;
if ((fp_book = fopen(book, "r")) == NULL) goto error3;
// Main loop
do {
ch = getc(fp_book);
if (isalpha(ch))
word[wlen++] = ch;
else {
if (charno <= wlen)
putc(toupper(word[fromstart ?
(charno - 1) : (wlen - charno)]), fp_cod);
wlen = 0;
}
} while (!feof(fp_book));
// Termination
fclose(fp_book); fclose(fp_cod); return 0;
// Error handling
error1: printf("USAGE: bkadd codfile bookfile [charno]\n"); return 1;
error2: printf("Can not open code file %s\n", argv[1]); return 1;
error3: fclose(fp_cod);
printf("Can not open book file %s\n", argv[2]); return 1;
}
Plaintext



O

B
S
Plaintext 
(hex) 
44 52 44
4F 42
42
53
Running key
H
E

M


N
Running key (hex)
48 
45 
52 
4D
49
4F 
4E
Ciphertext 
(hex)
0C 17 16 02 0B 0D
1D
Ciphertext
12 
23 
22 

11 
13 
29

Download 77.34 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling