Write C++ program: Lets create your first cipher!!! Cipher is an algorithm that you can use to encrypt and decrypt sensitive information. In an information system, sensitive information is stored in a 16-bit unsigned number, where bit-wise information is stored in following format, 9-bits are reserved for account number and 7-bits are reserved for customer ID.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
C C C C C C C A A A A A A A A A
a) Using bit wise operators, write a function to extract customer ID
b) Another function to extract account number.
c) Due to security concerns, you have been given a task to create a cipher. Write a function to encrypt the 16-bit number (X) using the following expression.
y = aX + b, consider a = 5 and b = 233
d) Write another function to decrypt the number and display the original number.
#include<iostream>
int extract_customer_ID(int number)
{
int new_number = number >> 7;
return new_number;
}
int extract_account_number(int number)
{
int new_number = number >> 9;
return new_number;
}
int encrypt_the_16(int number)
{
int a = 5, b = 233;
return number * a + b;
}
void decrypt_the_number(int number)
{
int a = 5, b = 233;
std::cout<<"The original number: "<<(number-b)/a<<std::endl;
}
Comments
Leave a comment