One of the methods used to encrypt a message is to use the message itself. We begin by providing a secret number that is used for the offset of the first letter and is known only to sender and receiver. This starting value is called a seed. For example, if we encode the word, CAT, we begin by finding the alphabetic value of each letter: 3, 1 and 20; and then use the value of the previous letter as an offset, with the first letter using the seed value.
Suppose the seed is 5:
C (3) (3 + 5[seed] = 8) H
A (1) (1 + 3[1st letter] = 4) D
T (20) (20 + 1[2nd letter] = 21) U
So the encoded message is HDU. It should be clear how, using the seed 5, it is possible to decode it easily.
Decode this message, without being told the seed:
X B M W W N B G C U A O O M W N W H C V R Y L S W A Q
DATA X B M W W N B G C U A O O M W N W H C V R Y L S W A Q
READ x$
DO
ix = INSTR(x$, " ")
IF ix THEN x$ = LEFT$(x$, ix - 1) + MID$(x$, ix + 1)
LOOP UNTIL ix = 0
PRINT x$
alpha2$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
FOR offset0 = 1 TO 25
PRINT offset0;
offset = offset0
c$ = LEFT$(x$, 1)
FOR ch = 2 TO LEN(x$) + 1
ix = INSTR(27, alpha2$, c$) - offset
c2$ = MID$(alpha2$, ix, 1)
PRINT c2$;
offset = INSTR(alpha2$, c2$)
c$ = MID$(x$, ch, 1)
NEXT
PRINT
NEXT
gives
1 WEHOHFVKRCXQXOHFQQLJHQUXYBO
2 VFGPGGULQDWRWPGGPRKKGRTYXCN
3 UGFQFHTMPEVSVQFHOSJLFSSZWDM
4 THEREISNOFUTUREINTIMETRAVEL
5 SIDSDJRONGTUTSDJMUHNDUQBUFK
6 RJCTCKQPMHSVSTCKLVGOCVPCTGJ
7 QKBUBLPQLIRWRUBLKWFPBWODSHI
8 PLAVAMORKJQXQVAMJXEQAXNERIH
9 OMZWZNNSJKPYPWZNIYDRZYMFQJG
10 NNYXYOMTILOZOXYOHZCSYZLGPKF
11 MOXYXPLUHMNANYXPGABTXAKHOLE
12 LPWZWQKVGNMBMZWQFBAUWBJINMD
13 KQVAVRJWFOLCLAVRECZVVCIJMNC
14 JRUBUSIXEPKDKBUSDDYWUDHKLOB
15 ISTCTTHYDQJEJCTTCEXXTEGLKPA
16 HTSDSUGZCRIFIDSUBFWYSFFMJQZ
17 GURERVFABSHGHERVAGVZRGENIRY
18 FVQFQWEBATGHGFQWZHUAQHDOHSX
19 EWPGPXDCZUFIFGPXYITBPICPGTW
20 DXOHOYCDYVEJEHOYXJSCOJBQFUV
21 CYNINZBEXWDKDINZWKRDNKAREVU
22 BZMJMAAFWXCLCJMAVLQEMLZSDWT
23 AALKLBZGVYBMBKLBUMPFLMYTCXS
24 ZBKLKCYHUZANALKCTNOGKNXUBYR
25 YCJMJDXITAZOZMJDSONHJOWVAZQ
where I've bolded the sensible line.
|
Posted by Charlie
on 2009-01-19 22:53:37 |