Title: CS100A Lecture 13 15 Oct. 1998
1CS100A Lecture 1315 Oct. 1998
- Discussion of Prelim 2
- (Tuesday, 20 October, 730-9PM)
- Rooms for Prelim 2
- A-K Hollister B14
- L-Z Kimball B11
- Cryptography
- Encryption-Decryption
- using arrays (assignment 6)
2- Prelim 2
- 1. Everything that was on Prelim 1. In
particular - Be able to define four kinds of variables local
variables, parameters, fields (instance
variables) and static fields (class variables) - Know the three kinds of methods (procedures,
functions, constructors) - Know what an argument is.
- Know precisely the steps in executing a method
call. - Know precisely the steps in evaluating new C()
- 2. Loops Know what a loop invariant is and how
it is used. Be able to write a loop, given an
invariant. Write simple loops without be given an
invariant. - 3. Arrays know how to declare an array, allocate
an array, use an array. - 4. Understand type char.
3CS100A Lect. 13, 15 Oct. 1998
- Cryptography
- Encryption-Decryption
- using arrays
- (assignment 6)
- Cryptography even before Caesars time Encode
messages, with the hope that only friends, who
have been given the decoding scheme, can decode
them. - Have a nice day
- replace every character by the next one a --
b, etc. - Ibwf b ojdf ebz
4During world war II, the Germans encoded messages
using a kind of computer (not a real computer,
as we know them today) they had built, called the
Enigma. The British had a group that worked
continu-ously to intercept and decode the
messages. They succeeded in breaking the code,
and this was one reason for the success of the
Allies. At times, they couldnt use what they had
learned because they didnt want the Germans to
suspect that their codes had been broken. Alan
Turing, a mathematician who did a lot for
computing (about 1936) even before computers were
developed, had a big part in this. Youll learn
about Turings contributions to the theory of
computing --the Turing Machine-- in CS481.
5- Two types of cryptosystems
- Secret key both the sender and the receiver
have the key to encoding/decoding. Hopefully, no
one else does. How to send the receiver the
secret key (assuming it has to be changed)
without others intercepting it? - Public key-private key Gries decides on a public
key - private key pair. He makes the public key
available to everyone. Anyone wanting to send
Gries an encoded message encodes it using the
public key. Only Gries, who knows the private
key, can decode the message. Diffie and Hellman
published the idea in 1976, but without a good
implementation. - RSA (by Ron Rivest, Adi Shamir, and Leonard
Adelman) found a way to implement it, using
number theory. This assignment concerns the RDA
public key - private key method.
6- long integers
- -9223372036854775808.. 9223372036854775807
- Public key (puk, m)
- Private key (prk, m)
- Examples
- puk prk m
- 401 137 551
- 229 349 399
- 241 481 551
- 109 493
-
- Send Gries/Cardie messages using public key (109,
493). Only they can decode them because only they
know the value prk. With small numbers, it can be
guessed, but remember that these can be long
integers --or even larger integers if we use some
other representation of itnegers in Java. - We dont show how to generate public key -
private key pairs. Must be hard to guess the prk.
For example, given two primes p1 and p2, its
easy to calculate p1p2. But, given p1p2, its
very hard to calculate p1 or p2! Easy to multiply
two integers hard to factor some integers.
7Arithmetic modulo m (for m0) Numbers can get
too big when encrypting and decrypting (bigger
than the biggest number in type long). We need a
way to keep integers small. Use arithmetic modulo
m, in which all integers are kept in the range
0..m-1. For any integer i, mod(i,m), or i
mod m , is the integer that satisfies i
qmr and 0mod 5 1 -4 mod 5 1 5 mod 5 0 0 mod 5
0 -5 mod 5 0 4 mod 5 4 -1 mod 5 4 3 mod
5 3 -2 mod 5 3 2 mod 5 2 -3 mod 5
2 To calculate (i mod m) If i 0 Use im
(remainder when i is divided by m) If iUse (im) m See method mod in class Crypto for
an analysis.
8Use arithmetic modulo m When encrypting and
decrypting, after EVERY opera-tion that might
produce an integer r that is larger than m,
reduce it modulo m, that is, use r mod m
instead! RSA To encrypt an integer i as an
integer j, use j i puk mod m To decrypt an
integer j to yield i, use i j prk mod m In
RSA, puk. prk, and m are chosen to guarantee that
i ( i puk mod m)prk mod m
9Encrypt a String s of characters as a long array
c0..s.length() Each element ci of c is the
encryption of si ((int) s.charAt(i)) puk mod
m To decrypt long array c and produce the String
s each character si is (char) (ci prk mod
m) Example the String CS100 with prk 401
and m 551 is encrypted as the array 383, 277,
197, 98, 98