Monday, September 21, 2020

CNOT Gate

 Controlled NOT gate: 

⏐x, y → ⏐x, x ⨂ y

Matrix:  

The CNOT maps 

⏐0 0  ⏐0 0
⏐0 1  ⏐0 1 
⏐1 0  ⏐1 1
⏐1 1  ⏐1 0

Proof:

⏐00 = [1 0 0 0], ⏐01 = [0 1 0 0], ⏐10 = [0 0 1 0], ⏐11 = [0 0 0 1], all vectors transposed for easy typing. 

Here ⏐0 == [1 0] and ⏐1 == [0 1] and ⏐ab = ⏐a ⨂ ⏐b

Apply matrix multiplications: 

CNOT × ⏐00  ⏐00
CNOT × ⏐01  ⏐01
CNOT × ⏐10  ⏐11
CNOT × ⏐11  ⏐10

#

In math, left Kronecker product ⨂ is


For example: 




Qubit Operation (2)

CNOT gate: to flip iff  (if and only if) the control quit is |1>, otherwise it does nothing. 


Entanglement:


⏐+ == [1/sqrt (2) * (|0> + |1>) == 0.707 |0> + 0.707 |1>

⏐- == [1/sqrt (2)] * (|0> - |1>)

X (a, b) = (b, a), NOT gate

|a, b> == |b, a>, see below qubit swap:


[a |0> + b |1>] |0> == a|00> + b|10>

|𝝍> == a |0> + b |1>

|𝝍>|𝝍> == a^2|00> + ab|01> + ab|10> + b^2|11>

Bell state (entanglement):







Linear Algebra - Qubit Operations

Vectors are commonly written in column format. Sometimes, we also use shorthand format such as (3, 4).

In quantum computing, the state |0> corresponds to vector (1, 0), and |1> corresponds to vector (0, 1). 

Commonly used quantum gates, quantum circuit symbols, and math representations: 


The Bloch sphere representation of X (NOT), H (Hadamard), and Z, S, T (phase) gates. 



We can see that 
  • X gate rotates along X axis 180 degree (or less depending on the initial angle to Z axis). (NOT) 
  • H gate rotates along Y  axis 90 degree (or less). 
  • Z, S, T gates rotate along Z axis at certain degree. (phase)


Monday, September 7, 2020

PGP Encryption

Developed by Phil Zimmerman in 1991. It combines symmetric, asymmetric (public key) encryption, hash, and digital signature all together providing confidentiality, integrity, and authentication. Good for email. The algorithm:

At the sender (Alice) side: 

  1. Alice: Message M is hashed
  2. Sign (encrypt) the hash value with her private key (EP)
  3. Compress (zip) the message + signed hash value
  4. Use a session key Ks to encrypt zipped output (ES)
  5. Use Bob's public key to encrypt session key (EP)
  6. Send encrypted message and encrypted session key 
At the recipient (Bob) side:
  1. Use Bob's private key to decrypt session key (DP)
  2. Use session key Ks to decrypt the zipped message
  3. unzip, got message and signed hash value
  4. Use Alice's public key to decrypt the hash value 
  5. Computing hash value for the message received
  6. Compare with hash value Alice computed.
Below are the PGP diagram:


Mathematically:

Note:
Image copyright: Author of this post. Free to use but reference is required. 

Tuesday, September 1, 2020

Quantum Circuit

 A quantum circuit is a computational routine consisting of coherent quantum operations on quantum data, such as qubits, and concurrent real-time classical computation. It is an ordered sequence of quantum gates, measurements, and resets, which may be conditioned on and use data from the real-time classical computation. A set of quantum gates is said to be universal if any unitary transformation of the quantum data can be efficiently approximated arbitrarily well as a sequence of gates in the set. Any quantum program can be represented by a sequence of quantum circuits and non-concurrent classical computation.

A quantum gate is a reversible (unitary) operation applied to one or more qubits.

Electronic computer: program --> instructions (operand and data) - binary bits
Quantum computer: program --> quantum circuits (quantum gate and quantum data) - qubits


Friday, August 28, 2020

Hashcat - Password Cracking

The labs shows how to crack hashed passwords using dictionary and brute-force methods on Kali Linux. 

Download hashcat-exercise-files.zip

sudo mkdir hashcat-exercise

unzip hashcat-exercise-files.zip

./view-sample-password.sh

echo -n salt [password] | md5sum

man crypt

man mkpasswd

A: Dictionary attack

Create text file test-dictionary with three words hello, wtaddtsbtk, dog in three lines. 

hashcat -m 500 -a 0 crack-these-please-md5 test-dictionary --force (cracked with 3 passwords)
hashcat -m 1800 -a 0 crack-these-please-sha512 test-dictionary (cracked with 3 passwords)

hashcat -m 500   -a 0 crack-these-please-md5     500_passwords.txt (cracked with 7 different)
hashcat -m 1800 -a 0 crack-these-please-sha512 500_passwords.txt (cracked with 7 different)

B: Brute force attack

openssl speed md5
openssl speed sha512

This shows md5 processes more data than sha512 in the same amount of time. 

hashcat -m 500 -a 3 crack-these-please-md5 ?l?l (mask ?l means one lowercase letter) return: w, ww
hashcat  -m  500  -a  3  crack-these-please-md5  ?a?a (?a all 95 characters on keyboards instead of 26)

Core attack modes

  • Dictionary attack - trying all words in a list; also called “straight” mode (attack mode 0, -a 0)
  • Combinator attack - concatenating words from multiple wordlists (mode 1)
  • Brute-force attack and Mask attack - trying all characters from given charsets, per position (mode 3)
  • Hybrid attack - combining wordlists+masks (mode 6) and masks+wordlists (mode 7); can also be done with rules
http://www-scf.usc.edu/~csci530l/instructions/lab-authentication-instructions-hashcat.htm

Saturday, June 20, 2020

The Rise and Fall of BlackBerry (phones)

Blackberry with its iconic on device full keyboard was a symbol of c-suite executives and other business professionals, the list also include the US Presidents. The reason for the wide adoption (some 10 years ago) was not only the beautiful design but also its security. 

Blackberry uses an end-to-end encryption called PGP. The servers are managed by a company (or a third party). When Alice sends a message, the message is firstly compressed. PGP then creates a (one time) random session key to encrypt the compressed message. The session key is then encrypted using Bob's public key and send to Bob. Bob uses his private key to decrypt the session key and uses it to decrypt the message. 

It is important to note that the encryption and decryption are done on Blackberry devices, we call end-to-end. Since PGP is strong encryption, men in the middle cannot decipher and read the message. Due to the strong security feature, Blackberry quickly gained the market popularity. 

Because PGP is too strong to break up, it prevents some countries or regimes to spy on their citizens. As a result, many countries banned to bring Blackberry to those countries. As a result, this beautiful device was quickly faded away. 

Some scientists believe the fall of Blackberry was not because its business malpractice. It was because the strong security and no back door. Technology may not always win. 

Final comments: 
1. The good news is PGP technology is still here and people can choose to use.  
2. Random number generation (RNG) is very important for the security of encryption key. Quantum RNG (QRNG) can guarantee the truly randomness. 
3. Compression is a form of encryption, usually symmetric, due to its fast speed. 
4. Learn more about PGP, visit Philip Zimmermann's website