coding-and-cryptography
coding-and-cryptography
I. MODULAR ARITHMETIC
A. MODULAR ARITHMETHIC
Modular arithmetic is a system of arithmetic for integers, where values reset to
zero and begin to increase again, after reaching a certain predefined value,
called the modulus (modulo).
1. Example 1:
2. Example 2:
(15 + 18) mod 9. When you add 15+18 the sum will be 33, then dividing it
to 9 will give you a quotient of 3 and remainder 6. When we follow the
equation, the result will be . To make it congruent, the
standard form will be (15+18) mod 9 6.
Look for a number that when you add to 9 would result to 15. In this
case, 6 would do. 9 + 6 = 15 and this would result to 0. Thus,
. Another alternative statement would
be . Because when you add 6 to 9 the result would
be 15 and it is congruent since 15 divided by 15 would equal to 0.
2. MULTIPLICATIVE INVERSE
a. Example 1:
Look for a number that when you multiply to 3 would have a remainder
of 1 when divided by 5. In this case, 2 would be the best answer since 2
multiplied to 3 would result to 6 and when it is divided by 5 it would get a
remainder of 1. Such that ( )( ) and it can also be
stated as
In the Philippines, the National Library of the Philippines (NLP) takes charge of
the ISBN registration, allocation and designation for Filipino publishers and
authors. The ISBN code’s format is
.
is the country code while the remaining digits except for are for
identifying the author and title of the book. is the check digit which can be
obtained using the formula:
(
)
[ ( ) ( ) ( ) ( ) ( ) ( )]
= 10 – 4
=6
E. CREDIT CARDS
Credit cards can be checked by doubling every other digit in of the credit card
number. In this way, you can determine whether the card is valid or not. Simply
add every digit including the double ones, which are also to be treated
separately. The credit card number will only be valid when the sum of all the
digits under modulo 10 is congruent to 0.
a. Example 1:
To determine whether the credit card number is valid, we first have to create
a table.
DIGITS 5 2 3 4 8 2 1 3 3 4 1 0 1 2 9 8
DOUBLED 10 2 6 4 16 2 2 3 6 4 2 0 2 2 18 8
DIGITS(ALTERNATE)
Sum = 1 + 0 + 2 + 6 + 4 + 1 + 6 + 2 + 2 + 3 + 6 + 4 + 2 + 0 + 2 + 2 + 1 + 8 + 8
= 60 0 mod 10
Since, the sum of all the digits is congruent to 0; the credit card number is
valid.
II. BINARY SYSTEM AND HAMMING CODES
The most commonly used digits in the binary system are 1 and 0. Although, there
are instances where 0 – 9 is used and even letters A to F which are commonly used
in programming languages.
A. BINARY SYSTEM
The Binary System is a special system that uses the digits 0 and 1.
Start by making a table that gradually divides 86 by 2. Also take note that in
getting the binary number, you start from the right which is why the binary
number for 86 is 1010110.
NEW 86 43 21 10 5 2 1
DECIMAL
QUOTIENT 43 21 10 5 2 1 0
REMAINDER 0 1 1 0 1 0 1
1 0 1 1 0
0 x 20 = 0
1 x 21 = 2
1 x 22 = 4
0 x 23 = 0
1 x 24 = 16
2210
B. BINARY SUM
Here are the sums of the elements:
SUM OF THE ELEMENTS BINARY SUM
0+0 0
0+1 1
1+0 1
1+1 10
2 is not a part of the binary system that is why 10 is the binary sum when you
add 1 to 1. The 2 digits which are 1 and 0 represent the value of 2.
a. Example 1:
C. BINARY CODES
Binary codes are strings of 1s and 0s. Each character in a string is called a bit
while a series of eight bits is called a byte.
To figure out a message in the coded words you have to group them first by 5
bits.
0110100001101000100000000010011001100000001101010101110
01101 00001 10100 01000 00000 01001 10011 00000 00110 10101 01110
D. HAMMING CODES
The Hamming code is used for correcting errors. This uses a redundant bit or also
known as parity bit.
a. Example 1:
Consider the bit 10010. Each digit will be named
consecutively.
P1 P2 D3 P4 D5 D6 D7 D8
DIGIT ? ? 1 ? 0 0 1 0
III. CRYPTOGRAPHY
Cryptography has been an important factor by means of communicating through the
internet. It has been relied upon a widespread of websites that ensures your safety.
A. CRYPTOGRAPHY
Cryptography involves in securing your data or information by converting them
into codes or unreadable formats. This also involves encryption that encodes a
message or info that only authorized parties can access and decryption that
recovers the encrypted information.
a. Example 1:
ENCRYPTION
Encrypt the phrase “MATH RULES” using a shift cipher K = 9.
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
Shift every letter from their assigned number on the table using the given
cipher formula which is C = (P + 9) mod 26.
Original M A T H R U L E S
Message
Original 12 0 19 7 17 20 11 4 18
Position
Shifted 21 9 2 16 0 5 20 13 27
Position
Encrypted V J C Q A F U N B
Message
b. Example 2:
DECRYPTION
Decrypt the phrase “GUNBLOFYM” using a shift cipher K = 20.
Use the formula P = (C – K) mod 26.
Original G U N B L O F Y M
Message
Original 6 20 13 1 11 14 5 24 12
Position
Shifted 12 0 19 7 17 20 11 4 18
Position
Encrypted M A T H R U L E S
Message
P = (6 – 20) mod 26
= -14 mod 26
-14 indicate that it is the additive inverse of 14 modulo 26. In this case,
-14 12 mod 26. The others will undergo the same process.
B. AFFINE CIPHER
This is basically cryptography made more complicated by adding multiplication
to make it more difficult to crack.
a. Example 1:
ENCRYPTION
C = (3*12 + 5) mod 26
C = (36 + 5) mod 26
C = 41 mod 26 = 15
Original M A T H R U L E S
Message
Original 12 0 19 7 17 20 11 4 18
Position
Shifted 15 5 10 0 4 13 12 17 7
Position
Encrypted P F K A E N M R H
Message
b. Example 2:
DECRYPTION
We use the formula P = (C – K) mod 26, where is the affine cipher which
is also the multiplicative inverse of m.
Using the previous affine cipher, the inverse will be (9, 5). The formula will
now be P = 9 (C – 5) mod 26.
Cipher Y A J H O X A V J A J F R
Message
Original 24 4 5 20 20 21 4 15 5 4 5 19 3
Position
Shifted 15 17 0 24 5 14 17 12 0 17 0 22 8
Position
Encrypted P R A Y F O R M A R A W I
Message
P = 9 (24 – 5) mod 26
= 9(19) mod 26
= 171 mod 26 = 15
This process is the same for the remaining letters.
SOURCES
https://www.coursera.org/lecture/mathematics-for-computer-science/3-106-additive-identity-
and-inverse-mod-k-d5o4
https://whatis.techtarget.com/definition/Hamming-code
https://www.youtube.com/watch?v=1A_NcXxdoCc
https://en.wikipedia.org/wiki/Encryption
https://www.computerhope.com/jargon/d/decrypti.htm
MATHEMATICS IN THE MODERN WORLD, CHAPTER 8, 260 - 291