Cryptographic Challenge: Base64 to Hex

cryptography

ChallengeBase64Hexadecimal
Your challenge is to write a piece of code, using the programming language of your choice, to code and to decode messages encrypted using Base 64 encoding and Hexadecimal (Base 16) encoding.

Your progamme will first ask the user if they want to encode or decode a message. It will then ask the user to enter either the plain text (using the base64 character set) or the ciphertext (hexadecimal).

Your program will then output the decoded (plaintext) or the encoded message (ciphertext).

For instance:
Plain:  Code/Breaker
Cipher:  0A875EFC1ADE6A47AB

The following diagram will help you understand how the conversion from Base 64 to Hexadecimal works:
cryptography-base64-hexadecimal

Code Breaking Challenge:
You will then be able to decrypt the following encoded message:

Cipher:
Plain Text:

Base64

Base64 is a binary-to-text encoding scheme where each character (plaintext) is coded using 6 bits of data. Hence a base64 character set contains exactly 64 characters:

Index Char Index Char Index Char Index Char
0 A 16 Q 32 g 48 w
1 B 17 R 33 h 49 x
2 C 18 S 34 i 50 y
3 D 19 T 35 j 51 z
4 E 20 U 36 k 52 0
5 F 21 V 37 l 53 1
6 G 22 W 38 m 54 2
7 H 23 X 39 n 55 3
8 I 24 Y 40 o 56 4
9 J 25 Z 41 p 57 5
10 K 26 a 42 q 58 6
11 L 27 b 43 r 59 7
12 M 28 c 44 s 60 8
13 N 29 d 45 t 61 9
14 O 30 e 46 u 62 +
15 P 31 f 47 v 63 /

Hexadecimal


Hexadecimal is a base-16 number system. The hexadecimal numbers are 0-9 and then use the letters A-F to represent the decimal values 10 to 15.

Each digit in hexadecimal can be coded in binary using 4 bits as follows:

Binary Decimal Hexadecimal
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F

Extension Task


Using the same approach, we can encode message in a range of encoding schemes such as Hexadeximal (4-bits per character), Base32 (5 bits per character), Base64 (6 bits per character), Extended ASCII (8 bits per character).

You can now update your code to cater for a range of encoding/decoding techniques between all these encoding schemes.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.6 / 5. Vote count: 16

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,