Ias102 Finals Lab-Activity
Ias102 Finals Lab-Activity
DATE: 11/28/2021
INSTRUCTIONS:
Make a cryptography that can encrypt and decrypt. Look for a sample codes and dissect this so we may know
how thus this work in terms of encryption and decryption. Explain in a step-by-step process how the algorithm
will encrypt and decrypt.
1. Substitution Cipher
The Caesar cipher is one of the most basic and well-known encryption methods, depending on the
shift, each letter is replaced by a different letter.
The provided shift number is 4 in this situation. Starting from A to B (1), B to C (2), C to D (3), D to E (4), the
ciphertext will begin with the letter E and progress through G, H, I, J, and so on.
The plaintext is now "HOTDOG". Look at the matching letter in the ciphertext, which is the first letter in our
plaintext, "H."
PT= HOTDOG
CT= LSXHSK
It's now time to decrypt the message. To decrypt the message, first locate the plaintext that corresponds to
the Ciphertext column. The first letter is 'L.'
2. Transposition Cipher
A transposition cipher is an encryption method in which the locations of plaintext units (often letters or
groups of characters) are moved according to a regular pattern, resulting in the ciphertext being a
permutation of the plaintext.
The first step is to count the number of letters to determine the numerical value. The word 'LOVE' consists of
six letters. This key will be used to determine the number columns.
Plot the plaintext message from left to right, filling in any blank spaces with any characters until the message is
complete. There are, however, no blank spaces in this.
Recognize the insertion sequence of the encrypted message. This should be done alphabetically. In this
situation, we have L-O-V-E, 2-3-4-1.
Because the letter-E is the first key in the alphabetical sequence, we must first obtain the letter under the
letter-E.
To decrypt a message, we must first determine the total amount of letters. We have a total of 12 letters in this
instance.
Divide the entire number of letters by the total number of letters in the key that serves as the column, which is
4 in this case, so 12/4 is 3 and we'll have 3 rows.
The ciphertext must be plotted downwards based on the number, then read from left to right to determine
the decrypted message, 'IAS IS THE BEST.'
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY
3. Exclusive OR
4. Vernam Cipher
The Vernam cipher is, in theory, a perfect cipher. Instead of a single key, each plaintext character is encrypted
using its own key. This key — or key stream — is randomly generated or is taken from a one-time pad, e.g. a
page of a book. The key must be equal in length to the plaintext message. The fact that each character of the
message is encrypted using a different key prevents any useful information being revealed through a
frequency analysis of the ciphertext.
To encrypt the message, each character of the plaintext and the key will need to be converted to a numeric
code. Fortunately, there are already coding schemes to do this, and we can use standard ASCII codes. As you
may already know, in the ASCII coding system, each character is given a numeric code. For example, the letter
'H' is 72. This number has a binary representation of 01001000 (using 8 bits).
To use the Vernam cipher, you will need to use an XOR operation. The operation's truth table is shown below:
To apply the Vernam cipher, each bit of the binary character code for each letter of the plaintext is XOR'd with
the corresponding bit of each letter of the binary character code for the corresponding character from the key
stream — this creates the ciphertext.
Encryption
In the below example, the message 'HELLO' will be encrypted using the key 'PLUTO'.
1. Obtain the binary ASCII character code for each letter of the plaintext:
Plaintext
H - 01001000
E - 01000101
L - 01001100
L - 01001100
O – 01001111
2. Obtain the binary ASCII character code for each letter of the key
Key
P - 01010000
L - 01001100
U - 01010101
T - 01010100
O – 01001111
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY
3. Carry out the XOR operation, applying it to each corresponding pair of bits:
Ciphertext:
The output is a series of bytes that can be interpreted in many ways. If they are interpreted as ASCII, some will
inevitably be characters that cannot be printed/displayed. If you try to code the Vernam cipher to encrypt or
decrypt a message (see the 'Coding challenge' section), you will need to find a solution for the print/display
problem. One option is to display the ciphertext as denary or hex values. In the worked example above, the
ciphertext could be displayed in denary as 24, 9, 25, 24, 0 or in hexadecimal (hex) as 18, 9, 19, 18, 00.
Decryption
1. Obtain the binary character code for each character of the ciphertext (here, you are converting from
the hex codes):
18 - 00011000
9 - 00001001
19 - 00011001
18 - 00011000
00 - 00000000
2. Obtain the binary character code for each letter of the key:
P - 01010000
L - 01001100
U - 01010101
T - 01010100
O - 01001111
3. Carry out the XOR operation, applying it to each corresponding pair of bits:
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY
The text used is The C Programming Language (1978 edition), and the tabula recta is the tableau. The plaintext
is "Flee at once".
The message is then sent as "JCVSR LQNPS". However, unlike a Vigenère cipher, if the message is extended,
the key is not repeated; the key text itself is used as the key. If the message is extended, such as, "Flee at once.
We are discovered", then the running key continues as before:
To
determine where to find the running key, a fake block of five ciphertext characters is subsequently added,
with three denoting the page number, and two the line number, using A=0, B=1 etc. to encode digits. Such a
block is called an indicator block. The indicator block will be inserted as the second last of each message.
(Many other schemes are possible for hiding indicator blocks.) Thus page 63, line 1 encodes as "AGDAB"
(06301).
This yields a final message of "JCVSR LQNPS YGUIM QAWXS AGDAB MECTO".