Sie sind auf Seite 1von 5

CIS014-6 Cryptography and Cryptoanalysis Practical 2

Overview

This practical focuses on conversion between string, decimal, hexadecimal and binary and
on One Time Pad encryption.

Coverting strings to decimal, to hexadecimal and to binary

In this section you will learn how convert strings into decimal, hexadecimal and into binary,
using ascii code.

Binary into decimal

Convert with your pen the following numbers expressed in binary into decimal:
00110001


01101010



Input two arrays a and b containing the two previous set of bits.
Then, type the following commands and describe what you obtain
c=bi2de(a)


d=bi2de(b)


e=bi2de(a, 'left-msb)


f=bi2de(b, 'left-msb)



Decimal into binary
Convert with your pen the following numbers expressed in binary into decimal:
15


7



Generate two arrays a and b of size 4x1 of random integer chosen in the interval from 1 to
256. Then, type the following commands and describe what you obtain.
c=de2bi(a)


d=de2bi(b)




e=de2bi(a, 'left-msb)



f=de2bi(b, 'left-msb)





Hexadecimal into decimal

Write down the hexadecimal numbers:



Convert the following numbers from hexadecimal to decimal and write down how to do it
3
C
A1
C2


Generate one array a of size 10x1 of random hexadecimal numbers. Ask help if in trouble!
Write down the code you use to do it.
(Tip: write all the hexadecimal numbers as strings and use the function randi to generate 10
random positions of the 16 letter string containing all the hexadecimal numbers.)














Type the following commands and write down the result commenting it.
c=hex2dec(a)




c=hex2dec(a.)





String into decimal

Use the function double and char to convert string into decimal and viceversa.
Convert the string Crypto is nice into decimal.
Convert the sequence of numbers (116 111 100 97 121 32 105 115 32 115 117
110 110 121) into a string.
Write down the results and your comments














Hexadecimal to text: discover a message

Find the message, given the hexadecimal code of it:
M= 54686973206973206E6F74206D792070617373776F7264
where each character is represented with 2 digits of the hexadecimal code.
TIPS: use the function reshape to obtain the message as an array of hexadecimal digits
arranged in n row and 2 columns as reported below for the first digits of the message:
M= 54
68
69
73
20
69
...
Write the MATLAB code and the message.














One Time Pad Encryption


Generate a key k using the randi function to encrypt the following message m=This is a
short message. Encrypt it with the One Time Pad.
Write the code and the result.










Suppose you are told that the One Time Pad encryption of the message "Tomorrow we
meet in London" is 0AD5D4E0C1FFDDFD4999EF9B3D8B2126C994ECA4B9F45AF71CD7.
What would be the one time pad encryption of the message "Today we met in Copenhagen"
under the same OTP key?
TIPS: use XOR function. Convert the output of the XOR from logical to double TYPE.














Given that the ASCII code in hexadecimal of Bob is 42 6F 62 and of Eve is 45 76 65, verify
that the hexadecimal of the Bob XOR Eve = 07 19 07.
Choose a possibly random key and encrypt with OTP the word Bob.
Show that XOR-ing the encryption of the word Bob with 07 19 07 and decrypting the result,
we find the word Eve.
Can you show it with algebra of XOR?

Das könnte Ihnen auch gefallen