for (ascii = 32; ascii <= 127; ascii++)
{
encypted = 32 + (ascii-32+offset) % 96;
}
In this simple computation, the offset (=4) is the encryption key.
ASCII Cæsar wheel 32 36 $ 48 0 52 4 64 @ 68 D 80 P 84 T 96 ` 100 d 112 p 116 t 33 ! 37 % 49 1 53 5 65 A 69 E 81 Q 85 U 97 a 101 e 113 q 117 u 34 " 38 & 50 2 54 6 66 B 70 F 82 R 86 V 98 b 102 f 114 r 118 v 35 # 39 ' 51 3 55 7 67 C 71 G 83 S 87 W 99 c 103 g 115 s 119 w 36 $ 40 ( 52 4 56 8 68 D 72 H 84 T 88 X 100 d 104 h 116 t 120 x 37 % 41 ) 53 5 57 9 69 E 73 I 85 U 89 Y 101 e 105 i 117 u 121 y 38 & 42 * 54 6 58 : 70 F 74 J 86 V 90 Z 102 f 106 j 118 v 122 z 39 ' 43 + 55 7 59 ; 71 G 75 K 87 W 91 [ 103 g 107 k 119 w 123 { 40 ( 44 , 56 8 60 < 72 H 76 L 88 X 92 \ 104 h 108 l 120 x 124 | 41 ) 45 - 57 9 61 = 73 I 77 M 89 Y 93 ] 105 i 109 m 121 y 125 } 42 * 46 . 58 : 62 > 74 J 78 N 90 Z 94 ^ 106 j 110 n 122 z 126 ~ 43 + 47 / 59 ; 63 ? 75 K 79 O 91 [ 95 _ 107 k 111 o 123 { 127 44 , 48 0 60 < 64 @ 76 L 80 P 92 \ 96 ` 108 l 112 p 124 | 32 45 - 49 1 61 = 65 A 77 M 81 Q 93 ] 97 a 109 m 113 q 125 } 33 ! 46 . 50 2 62 > 66 B 78 N 82 R 94 ^ 98 b 110 n 114 r 126 ~ 34 " 47 / 51 3 63 ? 67 C 79 O 83 S 95 _ 99 c 111 o 115 s 127 35 #
In olden times, encryption was accomplished using a wheel marked with characters. Use the programming technique to decrypt the following messages, by trying every possible key until the correct key is found. How do you know when the correct key has been found?
Message 1:
Ymnx%rjxxflj%htzqi%mf{j%gjjs%stsxjsxj1%tw%fs~%qfslzflj3%Qzhp~%ktw%~tz1%fy%qjfxy%ny,x%wjfifgqj&&
Message 2:
deiflaksfllleff74r4wgfiurk3i4w&(/UFu6rIywo8yhdowd
This search method is the most primitive way of decrypting
a message. In this case, the problem is trivial. The aim of
cryptography is to make this type of computation practically
impossible.
cfencrypt(in,out,key1,key2,key3,72);to a i) shorter, ii) longer value?
memset(workvec,0,bufsize);What happens if we change the initialization to a different value? Try changing to a different value in both the encrypt and decrypt functions. Does this make a difference? What happens if different initializations are used?
What you should see from this problem is just how fragile data transmission is when the data are encrypted. If a single byte is lost or altered, it can become impossible to recover the data.
/*****************************************************************************/
/* */
/* File: appl.cpp */
/* */
/*****************************************************************************/
#include "appl.h"
#include "globals.h"
#include "prototypes.h"
void MDPrint (unsigned char *digest);
/*****************************************************************************/
main ()
{ MD5_CTX context;
char buffer[bufsize];
unsigned char digest[16];
printf("Enter string:");
scanf("%[^\n]",buffer);
MD5_Init (&context);
MD5_Update (&context,buffer,bufsize);
MD5_Final (digest, &context);
MDPrint(digest);
}
/*****************************************************************************/
void MDPrint (unsigned char digest[16])
{ unsigned int i;
char buffer[36];
for (i = 0; i < 16; i++)
{
sprintf((char *)(buffer+2*i),"%02x", digest[i]);
}
printf("Message digest = %s\n",buffer);
}
| Multiple choice test - (weight 1) |
|---|