The Hardware Side of Cryptography

23 May 2008

Designing the Atbash encoder / decoder

Previously, i have derived both equations and schematic of ROT13 encoder/decoder. Today, i’ m going to derive another equations and schematic, which is Atbash cipher. Atbash cipher works based on substitution. The substitution table is generated by reversing the order of alphabetic character. Well, let’s see the truth table first.

Atbash Cipher Truth Table

Lets define input bits as [x1x2x3x4x5x6x7x8] and output bits as [y1y2y3y4y5y6y7y8]. We could see directly from truth table that [y1y2y3] always be the same as [x1x2x3]. Therefore, we can coclude that:



To complete the design Atbash encoder / decoder, First we have to completely derive equations for each of output bits, draw the circuit and test the circuit. We will proceed to that stage step by step.

First, we map y4 as a function of x4x5x6x7x8 into Karnaugh-Map diagram. That process results this diagram below.

Then we can define y4 as:

Second, the mapping of y5 as a function of x4x5x6x7x8 into Karnaugh-Map diagram results this diagram below.

The boolean function of y5 then defined as:

Third, the mapping of y6 as a function of x4x5x6x7x8 into Karnaugh-Map diagram results this diagram below.

The boolean function of y6 then defined as:

Forth, the mapping of y7 as a function of x4x5x6x7x8 into Karnaugh-Map diagram results this diagram below.

The boolean function of y7 then defined as:

Fifth, the mapping of y8 as a function of x4x5x6x7x8 into Karnaugh-Map diagram results this diagram below.

The boolean function of y8 then defined as:

Last, the complete circuit of Atbash Encoder / Decoder then drawn as follow

I have tested the schematic above, and it works the same as specification (truth table). You may freely use, modify and redistribute this design under the term of GNU Free Documentation License. You may view benchmarking results on links below.

BENCHMARKING

A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

RELATED STUFF

Reference:
Atbash Cipher

22 May 2008

The Design of ROT13 encoder

Filed under: encoding, logic gate — Tags: , , , , — edipermadi @ 1:32 pm

I have previously made an implementaion of ROT13 cipher using PIC16F84 micrococontroller. Yesterday, i came up with a new idea of another ROT13 implementation. I was thinking about designing ROT13 encoder using discrete combinational logic. Today, I sat hours and hours to draw and debug those circuits until it meets the specification.

First think first, to design an encoder we first look at the “expected” behaviour of encoder that called as truth table then derive the boolean equation of each bits with respected to every inputs. The truth table of ROT13 encoder is shown below.

If we denote inputs as [x1x2x3x4x5x6x7x8] and outputs as [y1y2y3y4y5y6y7y8], ke knew that:



Since we knew so, y1,y2 and y3 were not expecting special treatment from us. The rest of output bits will explained further step by step.

First, If we map y4 into Karnaugh Map, with respect to y4y5y6y7y8, we will get this picture below.

Next, we proceed to deriving boolean function of y4. The y4 output bit then defined as.

Second, the same procedure as before. If we map y5 with respect to y4y5y6y7y8 The respecive Karnaugh Map diagram would be:

The boolean function of y5 then defined as:

Third, the mapping of y6 with respects to y4y5y6y7y8 will results this picture below.

The boolean equation of y6 then defined as.

Fourth, the mapping of y7 with respects to y4y5y6y7y8 will results this picture below.

The boolean equation of y7 then defined as.

Fifth, the mapping of y8 with respects to y4y5y6y7y8 will results this picture below.

The boolean equation of y8 then defined as.

Finally, after we have all boolean equations of each output bits, we now could draw the schematic circuit of ROT13 encoder. The schematic is shown below, please click the picture to see the full sized one.

I have tested the circuit and it works the same as specification. You may download benchmarking results on links below. You may freely use, redistribute and modify this design including the pictures under the term of GNU Free Documentation License.

BENCHMARK

A, B, C, D, E, F, G, H, I, J, K, L, K, N, O, P, Q, R, S, T, U, V, W, X, Y, Z.

RELATED STUFF

Reference:
ROT13 Cipher

19 May 2008

Implementing Polybius Cipher using PIC16F84

Polybius cipher works the same as Tap Code Cipher. Each letter is represented by its coordinate in lookup table. To fit 26 characters into 5×5 lookup table we rounded down by combining I and J letter inside one cell. The basic lookup table of Polybius Cipher is shown below.

For more convinience usage, you may enlarge that basic lookup table into another 6×6 lookup table. The 6×6 lookup table capables to encapsulate both digits and letters. An outlining example of 6×6 lookup table is shown below.

I wrote a code of Polybius Cipher for PIC16F84 microcontroller using MPLAB v8.0. I’ve verified and simulated the program. It works the same as specification. The program comes in two version, first version implements basic polybius cipher and the second one implements modified (6×6) polybius cipher.

Test Vector:

  • Plain Text = HELLO WORLD
  • Ciher Text = 23 15 31 31 34 52 34 42 31 14

Screenshots are shown Below:

Plain Text Screenshot

Cipher text Screenshot

RELATED STUFF

Download:
Source Code v1.0
Source Code v2.0
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0

Reference:
Polybius Square

Official Website:
- Microchip

18 May 2008

The Implementation of Keyword Cipher on PIC16F84

Keyword Cipher simply works based on monoalphabetic substitution. The substitution table is generated dynamically from the key, by filling up substitution table with key and padding the rest with unused alphabetic character.

Substitution Table Example:

  • Key : SHIFTRY
  • input : ABCDEFGHIJKLMNOPQRSTUVWXYZ
  • output : SHIFTRYABCDEGJKLMNOPQUVWXZ

Vector Test Example:

  • Plain Text = ALAKAZAM CHARMANDER NIDORINO
  • Key = SHIFTRY
  • Cipher Text = SESDSZSG IASNGSJFTN JBFKNBJK

I wrote a code of keyword cipher for PIC16F84 using MPLAB v8.0. It was successfully simulated and works the same as specification. You may freely use the code under the term of GPL v3.0. Hopefully this post can help you to grab understanding on how keyword cipher was done in a microcontroller such PIC16F84. The both screenshots of Plain Text and Cipher Text are shown below

Plain Text

Cipher Text

RELATED STUFF

Download:
Source Code v1.0
Source Code v1.1
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0

Reference:
Keyword Cipher

Official Website:
- Microchip

17 May 2008

The Implementation of Atbash cipher on PIC16F84

Atbash is a simple substitution cipher. Cipher text is obtined by substituting Plain Text into substitution table. In Addition, substitution table is created by reversing the order of bits. Fortunately, Plain text can be obtained by the same method as ciphering. So you don’t need to spent another procedure for deciphering.

The substitution table is shown below.

Anyway, i also wrote a code of Atbash cipher on PIC16F84 microcontroller. I typed and simulated the code using MPLAB 8.0 and works well. Example and screenshots are shown below.

Example:

  • Plain Text : YOU KNOW, MY BOSS IS A REAL JERK I CAN NOT BELIEVE HE ASSIGNED ME A HELL OF PROJECT
  • Cipher Text : BLF PMLD, NB YLHH RH Z IVZO QVIP R XZM MLG YVORVEV SV ZHHRTMVW NV Z SVOO LU KILQVXG

Plain Text Screenshot

Cipher Text Screenshot

RELATED STUFF

Download:
Source Code v1.0
Source Code v1.1
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0

Reference:
Atbash Cipher

Official Website:
Microchip

16 May 2008

The Implementation of Tap Code on PIC16F84

Filed under: decoding, encoding, encryption — Tags: , , , , — edipermadi @ 10:20 am

Tap code is a way of propagating information through taps. This way of communication was commonly used by prisoners to communicate each other. Metal bars or walls were the common media to transmit tap code. This cipher is really simple, it was not intended to provide secure communication, it was just another way to transmit information.

The cipher text is encoded by two digits. First taps represent selected row and the second taps represent selected column. The plain text is outlined as 5×5 table. It contains alphabetic cipher except the “K” letter. The “K” letter was omitted to fix alphabetic character into 5×5 table. Therefore, “K” character always represented as “C”. In additition, “X” character was used to to separate each words. The outlining table is shown below.

However, there will be several problem when plain text contain lots of “K” and “X” characters, solve this problem by your self :D . And remember, never use this terribly weak cipher for your confidential data :) .

example:

Plain Text :

PIDGEY BEEDRILL NIDORINO CHARMANDER CHARMELEON CHARIZARD METAPOD

Cipher Text :

35 24 14 22 15 54 53 12 15 15 14 42 24 31 31 53 33 24 14 34 42 24 33 34 53 13 23 11 42 32 11 33 14 15 42 53 13 23 11 42 32 15 31 15 34 33 53 13 23 11 42 24 55 11 42 14 53 32 15 44 11 35 34 14

Screenshots are shown below

Plain Text

Cipher Text

RELATED STUFF

Download:
Source Code v1.0
Source Code v1.1
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0

Reference:
Tap Code

Official Website
- Microchip

14 May 2008

The Implementation of ROT13 cipher on PIC16F84

ROT13 or ROT-13 cipher is a classic and simple cipher. ROT13 works exactly the same as caesar cipher, except the shifting key was fixed to 13. We may say that ROT13 is a special case of Caesar Cipher :) . To encrypt, you simply shift plain text by 13. To decrypt you simply shiftback cipher text by 13. This simple cipher was pretty famous, you may find this cipher on online forum to hide offensive words or to avoid spoilers :8 .

I alse wote a ROT13 code for PIC16F84 microcontroller on MPLAB 8.0. I’ve simulated the program and it works perfectly the same as what i expected. You may download the source code on download section. You may freely use this code under the term of GPL v3.0 license. The screenshots are shown below.

Example

  • Plain Text : YOU KNOW, MY BOSS IS A REAL JERK I CAN NOT BELIEVE HE ASSIGNED ME A HELL OF PROJECT
  • Cipher Text : LBH XABJ, ZL OBFF VF N ERNY WREX V PNA ABG ORYVRIR UR NFFVTARQ ZR N URYY BS CEBWRPG

plain text

cipher text

Note : this cipher is extremly weak. Never use this to hide sensitive data! Use this cipher for jokes and fun :) .

RELATED STUFF

Download:
Source Code v1.0
Source Code v1.1
Source Code v1.2
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0

Reference:
ROT13 cipher

Official Website:
- Microchip

13 May 2008

The Implementation of Caesar Cipher on PIC16F84

Caesar cipher is a classic and simple encryption scheme. It works based on alphabet shifting. Cipher text is generated by shifting plain text by “key” unit which is secret. For example, if shifting key is 2, “A” becoming “C”, “B” becoming “D” and so on. The process is really easy to understand.

Besides software implementation, Caesar Cipher also applicable to programmable embedded hardware such microcontroller. I have coded a program of Caesar Cipher on PIC16F84. The code is shown on Download section. The simulation is done using MPLAB 8.0 from Microchip. Feel free to use it under the term of GPL 3.0 :D . As an example have a look this example:

Example:

  • Plain Text : YOU KNOW, MY BOSS IS A REAL JERK I CAN NOT BELIEVE HE ASSIGNED ME A HELL OF PROJECT
  • Key : 2
  • Cipher Text : AQW MPQY, OA DQUU KU C TGCN LGTM K ECP PQV DGNKGXG JG CUUKIPGF OG C JGNN QH RTQLGEV

Take a look on both two pictures below, it describes you how Plain text procesed into Cipher text.

Plain Text

Cipher Text

This is cipher is really insecure, never use this for sensitive data :) .

RELATED STUFF

Download:
Source Code v1.0
Source Code v1.1
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0

Reference:
Caesar Cipher

Official Website:
- Microchip

12 May 2008

An Implementation of ThreeWay (3-Way) cipher using PIC16F84

Filed under: encryption — Tags: , , , , — edipermadi @ 9:45 am

ThreeWay (3-Way) cipher is a block cipher that has been developed by Joan Daemen. This cipher has 96-bits length of block and key. This cipher does not employ feistel network at all. The design of this cipher was intended for efficient hardware and software implementation. This cipher is not patented, feel free to use this cipher :) .

If you look further, this cipher consists of 11 rounds of processes. Most of the process is about XORs, circular shifts and several fundamental boolean operation such NOTs and ORs. In addition, this cipher does not employ substitution table, hence it can easily implemented in various microcontroller without worrying about memory consuming issues.

ThreeWay (3-Way) cipher also run well on PICmicro’s microcontroller from microchip. This post will demonstrate you how to implement ThreeWay (3-Way) cipher on PIC16F84 microcontroller. If you are pretty curious, you may extend the algorithm to derive the boolean function for hardware implementation using combinational logic flatform.

The benchmarking result shown that each iteration of encrypting process takes 4112 cycles and 299 words of program memory, not too bad :D . Well, the screenshot is shown below.

The screenshot of ThreeWay (3-Way) cipher benchmarking result

RELATED STUFF

Download:
Source Code v1.0
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0

Reference
ThreeWay (3-Way) cipher
Joan Daemen

Official Website:
- Microchip

Simulator:
ThreeWay (3-Way) cipher Simulator

Blog at WordPress.com.