Article · October 008 citations reads 5,930 authors


Figure 2: Encoding the message ”DRDOBBS”


Download 77.34 Kb.
Pdf ko'rish
bet7/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)

Figure 2:
Encoding the message ”DRDOBBS”
using the Book cipher.
Listing Three
// bkdecode
#include
#include
#include
int main(int argc, char *argv[])
{
char codfile[_MAX_PATH];
char cipher[_MAX_PATH], decoded[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
FILE *fp_cipher, *fp_cod, *fp_decoded;
long position, cod_size;
// Argument processing
if (argc!=3) goto error1;
_splitpath(argv[1], drive, dir, fname, ext );
if (strlen(ext) == 0) strcpy(ext, "cod");
_makepath(codfile, drive, dir, fname, ext);
_splitpath(argv[2], drive, dir, fname, ext );
_makepath(cipher, drive, dir, fname, "cry");
_makepath(decoded, drive, dir, fname, "txt");
// File opening
if ((fp_cipher = fopen(cipher, "r")) == NULL) goto error3;
if ((fp_cod = fopen(codfile, "r")) == NULL) goto error3;
if ((fp_decoded = fopen(decoded, "w")) == NULL) goto error3;
// Determine codfile size
fseek(fp_cod, 0, SEEK_END);
cod_size = ftell(fp_cod);
// Main loop
while ((fscanf(fp_cipher, "%ld", &position) != EOF)) {
if (--position <= cod_size) {
fseek(fp_cod, position, SEEK_SET);
putc(getc(fp_cod), fp_decoded);
}
else goto error2;
}
// Termination
fclose(fp_cipher); fclose(fp_cod);
fclose(fp_decoded);
return 0;
// Error handling
error1: printf ("USAGE: bkdecode codfile cipher \n"); return 1;
error2: printf ("Invalid ciphertext\n");
fclose(fp_cipher); fclose(fp_cod);
fclose(fp_decoded); remove (decoded); return 1;
error3: printf ("Can not open files\n"); return 1;
}
The Book cipher algorithm uses letters of
subsequent words in some text or book as a key to
encode a message
D10deja_p5db 8/15/08 10:13 AM Page 50


October 2008
l

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