Array and Strings – Strings – Problem #14
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
It is unsafe to send data directly from one place to another. Therefore, we use encryption to convert the files/strings into an unreadable format which needs some key/ method to decrypt to get the actual file/string. Write a C program to encrypt a text string following the given steps: 1. Take a string as input (the string can contain alphabets and numbers) 2. Take the 8-bit binary representation of each character in the input string (you can use int i = (int)c; if c is a char) and concatenate all these bits to get an intermediate representation of the whole input string. 3. Then take each groups of 6-bits in the intermediate representation (starting from left-end towards the right) and map it using the following rules: 0 => A, 1 => B, ..., 25 => Z (Capital Letters) 26 => a, 27 => b, ..., 51 => z (Small Letters) 2 52 => 0, 53 => 1, ..., 61 => 9 (Numericals) Example: Input: IIT Kharagpur [Intermediate steps: 1. (int) ‘I’ is 73 2. 8-bit binary representation of 73 is 01001001 3. Hence, intermediate representation is 0100100101001001. . . 4. After converting first 6-bits from the intermediate representation, we get (010010)2 => (18)10 => S] Output: SUlUIEtoYXJhZ3B1cC Input: C Programming Output: QyBQcm9ncmFtbWluZC [Hint: You can consider a temporary integer array of size (8*number of characters of string) where you can store the intermediate bit representation, each bit as an integer 1 or integer 0 stored in each cell of the array]