You are on page 1of 4

Labwork4

Biomedical informatics
University of Ljubljana, Faculty of Electrical
Engineering

Autor:
dr. Tomaž Vrtovec Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies Registration number: 70081273
Academic year: 2018/2019
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

LabWork4: DATA ENCRYPTION


The main purpose of this lab is to learn how data encryption is carried out, and actually write some
decryption/encryption codes.

Question 1

This question asks to encrypt the text ’Biomedical informatics’ using ’encryption’ for the encryption
key and Base64 encoding. The code used is the same as the one written in the lab.

The encrypted plaintext is:

p9fS397U3czQ2oXX0djo4uHK49fI4Q

The encoded plaintext is:

QmlvbWVkaWNhbCBpbmZvcm1hdGljcw

Question 2
This question asks to decrypt the ciphertext
'uM3M5ZnZ54m7z8aFuuHr25S33pyEmYPX5+Td3dvTyIWm5PLg6NjW4MXVy+uZ1uPbj+LMyoPl7tLezt
LihKfM4ebV2NLSz9CFrODf3+bW0OLNyNag' using the key ’decryption’. The code used is the same as
the one written in the lab. The plaintext obtained is:
This is Lab Work No. 4 entitled Cryptography for the subject Biomedical Informatics.

Question 3

This third question asks to do some calculations related to the length in bytes of th texts obtained in
questions 1 and 2.
Plaintext: ’biomedical informatics’
Using the function length() we can see that ’biomedical informatics’ is has a total of 22 characters.
This means that it has 22 bytes or 22*8=176 bits.
Encoded text
The length of the encoded text is 30. This can be seen using once again the function length. However,
it is not really necessary to use that function, the length can be concluded from the previous result.
In fact, we know that when encoding, each byte is ’formed by only 6 bits’. Therefore, we have that
22*8/6= 30 bytes.
Ciphertext
Using the same logic used above, we have that the ciphertext is 112 bytes long.
Decrypted text
Using the same logic used above, we have that the decrypted text is 84 bytes long. This result can be
obtained either using the function length() or by doing some calculations. In fact, 112*6/8= 84 bytes.

1
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

Question 4

This question asks to write some arguments about the reason why Base64 scheme is used when
encoding.
Base64 schemes basically represent binary data in an ASCII string format by translating it into a
base64 representation. This means that all kind of characters can be mapped in a reable and
printable alphabet (a-z, A-Z, 0-9).

If a message is send in binary, the transmission can be considered as composed by 8bit characters, so
it is base256: each byte is a symbol from 0 to 255. This has one main problem: as some characterrs
have special meaning this coding cannot safely be attached to some channels. Therefore, instead of
using 8 bit digits, Base64 uses 6 bit words, having 64 possible combinations. These way, the ASCII
characters used are perfectly compatible with any channel.

Question 5

This last question asks to decrypt the following text using an


unkonwn key:
'qNbb1eGJw9vNgtnK1eGJ0M7Wx6eJrNzR0I2t0dKkgq/S1OHRgtHK1tKjgp6imJ+WkqSWk58'. The
only things we know about the text is that the plaintext contains the word ’John’ and that the key is
formed by three lowercase alphabet letters.
The programming code used has been the following one:
This exercise has been solved using the function decrypt_text(). This function has one input (the text
we want to decrypt) and two outputs (the decryption key and the decrypted text). First of all, a
vector called letters is created. This vector will then be used to form some keys. In fact, the following
three ’for’ create a different key in every loop (aaa, aab, aac … aba, aca, ada …). Once the key is
formed, the function decryptText() coded in the lab can be used. This function will give us a
decrypted text using the key that has been formed just before. To know whether the key was good,
we then have to see if the decrypted text contains the word ’John’. If it contains it, the key is OK and
we can go out of the loops. If it doesn’t we have to try another key. It is important to highlight that
since the Matlab version I have in my own computer is Matlab2016a I cannot use the function
contains() (it was included in the version Matlab2016b). I have therefore used the function strfind()
together with a ’if’ instead of the function contains().
Finally the key and decrypted texts are:
Key: ’bmi’
Decrypted text: ’First and last name: John Doe; Birth date: 1962-07-12’

2
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

close all; clear all; clc;


text=
'qNbb1eGJw9vNgtnK1eGJ0M7Wx6eJrNzR0I2t0dKkgq/S1OHRgtHK1tKjgp6imJ+WkqSWk58';
[Key,DecryptedText]=decrypt_text(text)

--------------------------------------------------------------------------------------------------------------------------------------
function [oKey,oText]=decrypt_text(iText)
letters = 'a':'z';
for i=1:length(letters)
for j=1:length(letters)
for k=1:length(letters)
Key(1)=letters(i);Key(2)=letters(j);Key(3)=letters(k);
oText=decryptText(iText,Key); % this function is the one coded
% in the lab
aux=strfind(oText,'John');
if aux~=0
break
end
end
if aux~=0
break
end
end
if aux~=0
break
end
end
oKey=Key;
end

You might also like