Sei sulla pagina 1di 2

University of Ljubljana, Faculty of Electrical Engineering

Master’s study programme in Electrical Enginnering (level 2)


Biomedical Engineering - Biomedical Informatics (64209) - Laboratory Practice

Lab Work 4: Cryptography


Prepared by: Tomaž Vrtovec https://e.fe.uni-lj.si

Instructions
Cryptography is the practice and study of techniques for secure communication related to various
aspects of data security, privacy and confidentiality. Basing on a simple algorithm, perform the
encryption and decryption of the given text with the selected key, and transform the results into
a usable form by encoding and decoding with the Base64 scheme.

1. Write a function for the encryption of a text message, i.e. plaintext:


function oText = encryptText(iText, iKey),

where the input argument iText represents the plaintext and iKey the encryption key, while
the output argument oText represents the ciphertext. To encrypt, add the numerical values
of the plaintext to those of the encryption key (repeat the encryption key to the length of
the plaintext when necessary).
Finally, the ciphertext has to be encoded with the Base64 scheme, for which you write a
function:
function oText = encodeBase64(iText),

where the input argument iText represents the text, while the output argument oText
represents the encoded text.
For conversion between numerical values and text characters use Matlab functions
unicode2native() and native2unicode(), while for conversion between the decimal and
binary base use Matlab functions dec2bin() and bin2dec(). The numerical values
and corresponding text characters for the Base64 scheme can be obtained from the
file tableBASE64.mat, e.g. in the form of a structure BASE64, where BASE64.charCode
represents numerical values and BASE64.charSymbol the corresponding text characters
(e.g. BASE64.charCode(13) = 12 and BASE64.charSymbol(13) = ’M’).

2. Write a function for the decryption of a text message, i.e. ciphertext::


function oText = decryptText(iText, iKey),

where the input argument iText represents the ciphertext and iKey the decryption key,
while the output argument oText represents the plaintext. To decrypt, subtract the nu-
merical values of the decryption key from those of the ciphertext (repeat the decryption
key to the length of the ciphertext when necessary).
Before decryption, the ciphertext has to be decoded with the Base64 scheme, for which
you write a function:
function oText = decodeBase64(iText),

where the input argument iText represents the text, while the output argument oText
represents the decoded text.
This procedure is reversed when compared to encryption, therefore you can use the same
Matlab functions as described under 1.

1
Questions
The answers to these problems have to be in the report along with the required figures and program code.

1. Encrypt the plaintext ’Biomedical informatics’ by the above described algorithm using
’encryption’ for the encryption key and Base64 encoding. Write down the obtained
ciphertext (i.e. encrypted and encoded plaintext).

2. Decrypt the ciphertext ’uM3M5ZnZ54m7z8aFuuHr25S33pyEmYPX5+Td3dvTyIWm5PLg6NjW4MXVy+u


Z1uPbj+LMyoPl7tLeztLihKfM4ebV2NLSz9CFrODf3+bW0OLNyNag’ by the above described algo-
rithm using Base64 decoding and ’decryption’ for the decryption key. Write down the
obtained plaintext.

3. In relation to questions 1. and 2., write down the length (in bytes) of the (a) plaintext,
(b) encrypted and encoded plaintext, (c) ciphertext, and (d) decoded and decrypted
ciphertext. Provide adequate arguments for your answers in connection to the length of
the initial message (plaintext or ciphertext).

4. Why is it useful to encode using the Base64 scheme? Provide adequate arguments.

5. The message ’qNbb1eGJw9vNgtnK1eGJ0M7Wx6eJrNzR0I2t0dKkgq/S1OHRgtHK1tKjgp6imJ+WkqSWk


58’ represents a text that was encrypted and encoded by the above described algorithms
using an unknown encryption key. By using the brute force search (trying out all possible
combinations), decrypt the text and find the encryption key, if you know that the plaintext
contains the word ’John’ and that the key is composed of exactly three lowercase alphabet
characters (letters = [’a’:’z’]). To search for the string of characters within a text
you can use the Matlab function contains().
Enclose the programming code and write down the encryption key and the decrypted text.

Additional Problems
The answers to these problems do not need to be in the report, but should serve to better understand the topic.

The Base58 encoding scheme is, in comparison to the Base64 scheme, adapted to avoid non-
alphanumerical as well as alphanumerical symbols that can be ambiguously interpreted. As
a result, symbols + (plus), / (slash), 0 (digit zero), O (uppercase o), I (uppercase i) and l
(lowercase L) do not appear in the Base58 scheme. Such encoding is used e.g. for BitCoin
currency addresses and for generating short web addresses on Flickr.
Write the functions for encoding and decoding according to the Base58 scheme that is stored
in the file tableBASE58.mat. Take into account that the Base58 scheme is intended for encoding
integer numbers into text and decoding text into integer numbers, and is based on searching for
the remainder after division by 58.

Potrebbero piacerti anche