Chapter 5. The Beauty of Codes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Chapter 5.

The Beauty of Codes

Introduction

In today’s digital world, where data security is crucial and


information flows smoothly across networks, the significance of
coding and cryptography cannot be overstated. These two
disciplines play a crucial role in the protection of private data, the
issuance of identifying numbers, and the security of our digital life.

Coding has evolved into the language of innovation and growth in a


world that is more and more dependent on technology. This skill
allows us to create the software, websites, and applications that
run our daily lives. It is the art of creating instructions that
computers can comprehend and carry out. A person or
organization's ability to code gives them the capability to realize
ideas, automate procedures, and resolve challenging issues.

On the other hand, cryptography provides an additional degree of security for our
online communications. Information is encrypted and decrypted using codes and
algorithms, rendering it illegible to unauthorized people. Sensitive data, including
private communications, financial transactions, and personal data, are protected
using cryptographic techniques. Without cryptography, our online actions would
be open to monitoring, manipulation, and exploitation.

In addition, codes act as identification numbers in a variety of scenarios in addition


to only protecting data. These alphanumeric representations are essential for
organizing and tracking data, from product tags, barcodes, and QR codes to
distinctive identifiers given to people like social security numbers and national
identity numbers. In industries like healthcare, logistics, retail, and many others,
they facilitate procedures, improve efficiency, and guarantee accuracy.

This module introduces us into the complexities of coding and encryption, illuminating their importance in our
everyday lives. It will help us discover the beauty and secrets of codes and see how they can revolutionize the modern
digital world

1. Coding

1.1 Coding Schemes

Coding schemes play a crucial role in representing information using various formats. They provide a systematic way
of encoding data for efficient storage, transmission, and processing. In this module, we will explore different types of
coding schemes, including binary coding, ASCII coding, Gray coding, and BCD coding.

a) Binary Coding: Binary coding is the most fundamental and widely used coding scheme. It represents
information using only two symbols, typically 0s and 1s. Each digit in a binary code is known as a bit (short for
binary digit). By combining bits, we can represent any type of data, such as numbers, text, images, and more.
Binary coding forms the basis of all digital systems and computer operations.

Example: The decimal number 10 is represented as 1010 in binary code.

b) ASCII Coding: ASCII (American Standard Code for Information Interchange) coding is a character encoding
scheme that maps characters to their corresponding numeric values. It was developed to standardize the
representation of characters used in computer systems. In ASCII, each character is assigned a unique 7-bit or 8-
bit binary code.
Example: The ASCII code for the letter 'A' is 65 (or 01000001 in binary).
c) Gray Coding: Gray coding, also known as reflected binary code, is a coding scheme used to minimize errors
in analog-to-digital and digital-to-analog conversions. In Gray coding, adjacent codes differ by only one bit,
reducing the chance of errors caused by signal noise. It is commonly used in applications where accurate
representation of analog signals is critical, such as in analog-to-digital converters.

Example: Gray coding for a 3-bit binary number is as follows:


Binary: 000, 001, 010, 011, 100, 101, 110, 111
Gray: 000, 001, 011, 010, 110, 111, 101, 100

d) BCD Coding: BCD (Binary-Coded Decimal) coding is a scheme


for encoding decimal digits using binary representation. It
assigns a unique 4-bit binary code to each decimal digit from
0 to 9. BCD coding is often used in applications where precise
decimal representation is required, such as in calculators and
digital displays.

Example: The BCD code for the decimal number 7 is 0111.

Coding schemes are essential tools for representing information in various forms. Binary coding forms the foundation
of all digital systems, while ASCII coding facilitates the representation of characters. Gray coding reduces errors in
analog-to-digital and digital-to-analog conversions, and BCD coding enables accurate decimal representation.
Understanding different coding schemes is crucial for programmers and engineers working with digital data.

1. 2. Identification Numbers

Identification numbers play a crucial role in various domains, allowing for unique identification and tracking of
individuals, books, and products. In this module, we will explore three significant identification numbers: Social
Security Numbers (SSNs), International Standard Book Numbers (ISBNs), and Universal Product Codes (UPCs). We will
delve into their structures, purposes, and how they are used in their respective fields.

a. Vehicle Plate Number


Structure
In the Philippines, vehicle plate numbers consist of a combination
of letters and numbers. The format of the plate number varies
depending on the type of vehicle and the region it is registered in.
Here are the common formats:

 Private Vehicles:
 The current standard format for private vehicles in most regions is LLL NNN (e.g., ABC 123).
 The first three letters represent the region or city where the vehicle is registered, while the three numbers
are usually assigned sequentially.
 Public Utility Vehicles (PUV):
 PUVs, such as buses and jeepneys, have a different plate number format. It typically consists of two parts:
the region or city code and the alphanumeric series.
 The region or city code is typically a letter or two that represents the specific location where the vehicle is
registered.
 The alphanumeric series can vary in length and includes a combination of letters and numbers.
 Motorcycles:
 Motorcycle plate numbers follow a different format than other vehicles.
 The standard format is LL NNNN (e.g., AB 1234), where the first two letters represent the region or city
code, followed by four numbers.
Purpose:
The primary purpose of vehicle plate numbers is to provide a unique identification for each registered vehicle in
the Philippines. These plate numbers help law enforcement agencies, traffic enforcers, and other authorities in
identifying and monitoring vehicles for various purposes, including:
 Traffic Enforcement: Plate numbers are used by traffic enforcers to identify vehicles that violate traffic rules
and regulations. They help in enforcing traffic laws and regulations, including parking violations, speeding,
and other traffic offenses.
 Vehicle Registration: Plate numbers are linked to a specific vehicle's registration information, including
ownership details and vehicle specifications. When a vehicle is registered with the Land Transportation
Office (LTO), it is assigned a unique plate number that remains with the vehicle throughout its lifespan.
 Identification and Tracking: Plate numbers aid in identifying and tracking stolen or involved vehicles in
criminal activities. Authorities can use plate numbers to trace the registered owner and track down the
vehicle if it is reported as stolen or used in illegal activities.
 Public Safety: Plate numbers also play a role in public safety by allowing citizens to report reckless driving,
hit-and-run incidents, or other traffic-related concerns to the authorities. Witnesses can provide plate
numbers as crucial information for reporting such incidents.

Note: The Philippine government periodically updates and revises the design and format of vehicle license plates to
enhance security measures and combat illegal activities

b. International Standard Book Number (ISBN):


Structure:
 The International Standard Book Number
(ISBN) is a unique numeric identifier assigned
to books and related products.
 The current ISBN standard is a 13-digit
number, although ISBNs were previously
assigned with a 10-digit format.
 The ISBN structure consists of five parts
separated by hyphens: prefix element,
registration group element, registrant element,
publication element, and check digit.

Purpose:
 ISBNs are used to uniquely identify books, e-books, audiobooks, and other published works.
 Publishers, distributors, and retailers rely on ISBNs to track inventory, sales, and order processing.
 Libraries and bibliographic databases use ISBNs to organize and retrieve information about books.
 ISBNs facilitate the discovery and cataloging of books by providing a standardized identification system.

c. Universal Product Code (UPC)

Structure:
 The Universal Product Code (UPC) is a barcode system used for
product identification and inventory management.
 UPCs are typically represented by a series of bars and spaces that
can be scanned by barcode readers.
 The structure of a UPC consists of three parts: the manufacturer
code, the product code, and the check digit.

Purpose:
 UPCs are used by retailers to track products in their inventory and at
the point of sale.
 The unique identification provided by UPCs helps retailers manage
stock levels, automate inventory processes, and analyze sales data.
 Consumers can scan UPCs with smartphones or barcode scanners to
obtain product information, compare prices, or make purchases online.
 Manufacturers use UPCs to differentiate their products, monitor sales, and track distribution channels.

Identification numbers like Vehicle plate numbers, International Standard Book Numbers (ISBNs), and Universal
Product Codes (UPCs) are vital in various fields. Vehicle plate numbers provide a unique identification for each
registered vehicle in the Philippines. ISBNs uniquely identify books, facilitating efficient inventory management and
accurate information retrieval. UPCs provide a barcode system that enables retailers to track products and streamline
sales processes.

2. Cryptography

2.1. Introduction to Cryptography

Cryptography is the practice of securing communication and data


through various techniques. It involves converting information into a
format that is unreadable to unauthorized parties, ensuring
confidentiality, integrity, and authentication.

a. Definition and purpose of cryptography

Cryptography is the science of encoding and decoding information to protect its confidentiality, integrity, and
authenticity. It involves mathematical algorithms and processes to transform plaintext (readable data) into
ciphertext (encrypted data) and vice versa.

Purpose:

 Confidentiality: Cryptography ensures that only authorized individuals can access sensitive information by
encrypting data, making it unreadable to unauthorized parties.
 Integrity: Cryptography provides mechanisms to verify that the information has not been tampered with
during transmission or storage. It ensures that data remains intact and unaltered.
 Authentication: Cryptography enables verifying the identity of individuals or systems, ensuring that the
information comes from a trusted source and has not been modified by unauthorized entities.

b. Importance of Confidentiality, Integrity, and Authentication

 Confidentiality:
 Confidentiality prevents unauthorized access to sensitive information.
 It ensures that only authorized parties can decrypt and read the information.

Examples: Protecting personal information, financial transactions, classified documents, trade secrets, etc.

 Integrity:
 Integrity ensures that data remains unchanged and unaltered during transmission or storage.
 It provides mechanisms to detect any unauthorized modifications to the information.

Examples: Maintaining the integrity of digital signatures, preventing unauthorized tampering with critical
systems, etc.

 Authentication:
 Authentication verifies the identity of individuals or systems.
 It ensures that the information received comes from a trusted source.

Examples: User authentication for secure access to systems, verifying the authenticity of digital certificates,
etc.
Cryptography plays a crucial role in securing communication and data. It provides confidentiality, integrity, and
authentication to protect sensitive information from unauthorized access and tampering. Understanding the purpose
and importance of cryptography is essential in today's digital world to ensure secure and trusted communication.

2.2. Encryption Techniques:

Encryption is the process of converting plain text or data into an unreadable format to prevent unauthorized access.
It plays a crucial role in securing sensitive information and ensuring data confidentiality.

a. The Caesar cipher

The Caesar cipher is a simple substitution cipher technique where each letter in the plaintext is shifted a certain
number of positions down or up the alphabet. It is named after Julius Caesar, who is said to have used this cipher
to communicate with his generals. The shift value used in the Caesar cipher is typically referred to as the "key."

Here's an example of how the Caesar cipher works:

Let's say we have a plaintext message: "HELLO" and we want to encrypt it using a Caesar cipher with a shift of 3.

 First, we assign each letter a numeric value based on its position in the alphabet (A = 0, B = 1, C = 2, and so
on). In this case, "H" is 7, "E" is 4, "L" is 11, and "O" is 14.
 Next, we apply the shift of 3 by adding 3 to each numeric value. So, 7 becomes 10, 4 becomes 7, 11
becomes 14, and 14 becomes 17.
 We convert these new numeric values back into letters using the alphabet. So, 10 becomes "K," 7 becomes
"H," 14 becomes "O," and 17 becomes "R."
 Finally, we combine these letters to get the encrypted message, which is "KHOOR."

To decrypt the encrypted message, we would simply reverse the process. In this case, we would subtract 3 from
each numeric value and convert them back into letters.

The Caesar cipher is a basic and easily breakable encryption method, as there are only 25 possible shifts. It can be
cracked through brute-force by trying all possible shifts or using frequency analysis, where the frequency of letters
in the encrypted message is compared to the expected frequency of letters in the language of the plaintext.

Despite its simplicity and lack of security, the Caesar cipher is still a useful teaching tool to introduce the concept of
encryption and substitution ciphers.

Example: Encrypt the message "thou shall not cheat" using Caesar cipher shift 5

Using a Caesar Cipher with a shift of 5, the encryption process involves shifting each letter in the
message 5 positions to the right in the alphabet.

Original message: "thou shall not cheat"

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Encryption process:
't' 19 + 5 = 24 'y' 'n' 13 + 5 = 18 's'
'h' 7 + 5 = 12 'm' 'o' 14 + 5 = 19 't'
'o' 14 + 5 = 19 't' 't' 19 + 5 = 24 'y'
'u' 20 + 5 = 25 'z' 'c' 2 + 5 = 7 'h'
's' 18 + 5 = 23 'x' 'h' 7 + 5 = 12 'm'
'h' 7 + 5 = 12 'm' 'e' 4 + 5 = 9 'j'
'a' 0 + 5 = 5 'f' 'a' 0 + 5 = 5 'f'
'l' 11 + 5 = 16 'q' 't' 19 + 5 = 24 'y'
'l' 11 + 5 = 16 'q'
Encrypted message: "ymtz xmfqq sty hmjfy"

To decrypt the encrypted message, we would simply reverse the process. In this case, we would subtract 5 from
each numeric value and convert them back into letters

b. The Decimation Cipher

The Decimation Cipher is a simple substitution cipher that operates on the principle of removing every nth
character from a message and then concatenating the remaining characters to form the encrypted message. The
value of n is typically referred to as the "decimation factor."

Here's an example of how the Decimation Cipher works with a decimation factor of 3:

Original message: "HELLO WORLD"

 Remove every third character: "HELRDL"


 Concatenate the remaining characters: "HELRDL"

The resulting encrypted message would be "HELRDL."

To decrypt the message, you would need to know the value of the decimation factor and then reverse the process.
In this case, you would insert two characters between each of the remaining characters to obtain the original
message.

It's worth noting that the Decimation Cipher is a relatively weak form of encryption since it only involves a simple
substitution and can be easily deciphered through frequency analysis and other techniques. It's more commonly
used as a puzzle or educational exercise rather than for secure communication.

Today, encryption techniques can be broadly classified into three categories: symmetric key encryption, asymmetric
key encryption, and hash functions.

3. Check Digits for Error Detection

Purpose and Benefits of Check Digits

Check digits are used in various identification numbers and barcodes to ensure the accuracy and integrity of data
during transmission and storage. The main purpose of check digits is to detect errors, such as transcription mistakes
or data corruption, that may occur during the handling of numeric codes. By including a check digit, the system can
identify if an error has occurred and take appropriate action to correct it. The benefits of using check digits include:

a) Error detection: Check digits help identify errors, such as single-digit substitutions, transpositions, or other
types of errors, in identification numbers. They act as a simple and efficient way to validate data integrity.
b) Data accuracy: Check digits improve the accuracy of data by providing a quick method to verify the
correctness of identification numbers. They reduce the likelihood of processing incorrect or invalid data.
c) Cost savings: By detecting errors early on, check digits can help prevent costly consequences, such as
shipping errors, billing mistakes, or incorrect data analysis. They contribute to increased efficiency and
reduced operational costs.

Modulo Arithmetic

Calculating and Verifying Check Digits: Modulo arithmetic is a mathematical operation used to calculate and verify
check digits. It involves performing calculations using remainders.

To calculate a check digit, follow these steps:


a. Assign weights to each digit in the identification number, starting from the rightmost digit.
b. Multiply each digit by its corresponding weight.
c. Sum up the products obtained in step b.
d. Divide the sum by a predefined modulus (usually 10 or 11).
e. Take the remainder from step d and subtract it from the modulus.
f. The result is the check digit.

To verify a check digit, follow these steps:


a. Remove the check digit from the identification number.
b. Calculate the check digit using the remaining digits (using the same method as calculating check digits).
c. Compare the calculated check digit with the original check digit.
d. If they match, the identification number is considered valid. Otherwise, an error has occurred.

Examples of Check Digits in Various Identification Numbers

Check digits are used in a wide range of identification numbers. Here are some examples:
a) Credit Card Numbers: Credit card numbers typically have a check digit calculated using the Luhn algorithm.
The check digit is used to detect common errors, such as single-digit errors and transpositions, during data
entry. Verifying the check digit ensures the accuracy of the credit card number.
b) International Standard Book Numbers (ISBN): ISBNs are unique identifiers used to identify books. The last
digit of an ISBN is the check digit. It is calculated using the modulus 11 arithmetic and is used to validate the
correctness of the ISBN.
c) Vehicle Identification Numbers (VIN): VINs are used to identify individual vehicles. The ninth digit of a VIN is
the check digit. It is calculated using a specific algorithm, which varies depending on the vehicle
manufacturer. Verifying the check digit helps ensure the accuracy of the VIN.
d) Barcodes: Some barcodes, such as the Universal Product Code (UPC), include a check digit. The check digit is
calculated using specific algorithms, such as the modulo 10 or modulo 11 check digit algorithms. Verifying
the check digit helps prevent scanning errors and ensures the integrity of the barcode data.

Check digits play a crucial role in error detection and data integrity for various identification numbers. Understanding
the purpose, benefits, and methods of calculating and verifying check digits is essential for ensuring the accuracy and
reliability of data.

For you: Bring in products with UPC barcodes or credit cards. In class, examine these items, identify the check
digits, and discuss their role in error detection.

You might also like