Coherence
Search…
Block-ciphers

Block ciphers

In order to understand hex and type parameters read Hash
In order to understand encryption and decryption read Stream

AES

spec
Description: Block cipher and AES winner.
Key:128, 192, 256 bits.
Iv: 128 bits.
Uses: General propuse, Performance is impportant, FIPS 197, NIST.

RC6

spec
Description: Block cipher and AES finalist.
Key: 128, 192, 256 bits.
Iv: 128 bits.
Uses: General propuse, alternative to AES.

MARS

spec
Description: Block cipher and AES finalist.
Key: 128, 192, 256 bits.
Iv: 128 bits.
Uses: General propuse, alternative to AES.

Twofish

spec
Description: Block cipher and AES finalist.
Key: 128, 192, 256 bits.
Iv: 128 bits.
Uses: General propuse, alternative to AES.

Serpent

spec
Description: Block cipher and AES finalist.
Key: 128, 192, 256 bits.
Iv: 128 bits.
Uses: General propuse, alternative to AES.

CAST-256

spec
Description: Block cipher and AES finalist.
Key: 256 bits.
Iv: 128 bits.
Uses: General propuse, alternative to AES.

Camellia

spec
Description: Block cipher, The cipher has been approved for use by the ISO/IEC, the European Union's NESSIE project, the Japanese CRYPTREC.
Key: 128, 192, 256 bits.
Iv: 128 bits.
Uses: General propuse, alternative to AES.

Speck128

spec
Key: 128, 192, 256 bits.
Iv: 128 bits.
Uses: IoT

Simeck64

spec
Key: 128 bits.
Iv: 64 bits.
Uses: IoT

Modes of Operation

CTR

spec
Description: Block cipher mode
Uses: Performance is important.

GCM

spec
Description: Block cipher mode
Uses: Authenticated encryption.
  • It only support "type":"string"
  • It doesn't support "algorithm":"SIMECK64"

How to ???

1
#!/usr/bin/env python
2
3
import requests
4
import json
5
import os,binascii
6
7
def sending(message):
8
url = 'http://127.0.0.1:6613/'
9
response = requests.post(url, data=message)
10
print response.content
11
return response.content
12
13
def stream(data_js):
14
req=json.loads(data_js)
15
print "Enc \n " + json.dumps(req) +"\n"
16
data_js_n=sending(json.dumps(req))
17
answ=json.loads(data_js_n)
18
print "Recived enc: \n" + (json.dumps(answ)) +"\n\n\n"
19
dec='{"algorithm":"AES","plaintext":"","iv":"b05691ef92cb9c9bb05691ef92cb9c9b",\
20
"version":1,"key":"b05691ef92cb9c9bb05691ef92cb9c9b","operation":"dec","type":"string", "mode":"ctr"}'
21
req=json.loads(dec)
22
req["plaintext"]=answ["result"]
23
print "Dec \n " + json.dumps(req) +"\n"
24
data_js_n=sending(json.dumps(req))
25
answ2=json.loads(data_js_n)
26
print "Recived dec: \n" + (json.dumps(answ2)) +"\n\n\n"
27
28
29
data_js='{ "version": 1 , "algorithm":"AES" , "type":"string", "plaintext": "Hello world!", "hex": 0,"operation":"enc",\
30
"key":"b05691ef92cb9c9bb05691ef92cb9c9b","iv":"b05691ef92cb9c9bb05691ef92cb9c9b", "mode":"ctr" }'
31
stream(data_js)
Copied!
In this example we encrypt and decrypt Hello world! string using AES with the key and iv given in CTR mode.
On datajs["algorithm"] can be one of {AES, RC6, MARS, Twofish, SERPENT, CAST256, CAMELLIA, SPECK128, SIMECK64 }_
1
#!/usr/bin/env python
2
3
import socket
4
import json
5
import os,binascii
6
7
def sending(message):
8
ip = '127.0.0.1'
9
port = 6613
10
BUFFER_SIZE = 65536
11
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12
s.connect((ip, port))
13
s.send(message)
14
data = s.recv(BUFFER_SIZE)
15
s.close()
16
return data
17
18
def stream(data_js):
19
req=json.loads(data_js)
20
print "Enc \n " + json.dumps(req) +"\n"
21
data_js_n=sending(json.dumps(req))
22
answ=json.loads(data_js_n)
23
print "Recived enc: \n" + (json.dumps(answ)) +"\n\n\n"
24
dec='{"algorithm":"AES","plaintext":"","iv":"b05691ef92cb9c9bb05691ef92cb9c9b",\
25
"version":1,"key":"b05691ef92cb9c9bb05691ef92cb9c9b","operation":"dec","type":"string", "mode":"gcm" ,"adata":"ABCD"}'
26
req=json.loads(dec)
27
req["plaintext"]=answ["result"]
28
print "Dec \n " + json.dumps(req) +"\n"
29
data_js_n=sending(json.dumps(req))
30
answ2=json.loads(data_js_n)
31
print "Recived dec: \n" + (json.dumps(answ2)) +"\n\n\n"
32
33
34
data_js='{ "version": 1 , "algorithm":"AES" , "type":"string", "plaintext": "Hello world!", "hex": 0,"operation":"enc",\
35
"key":"b05691ef92cb9c9bb05691ef92cb9c9b","iv":"b05691ef92cb9c9bb05691ef92cb9c9b", "mode":"gcm" ,"adata":"ABCD"}'
36
stream(data_js)
Copied!
In this example we encrypt and decrypt Hello world! string using AES with the key,iv,adata given in GCM mode.
On datajs["algorithm"] can be one of {AES, RC6, MARS, Twofish, SERPENT, CAST256, CAMELLIA, SPECK128}_
Json to enc string (key and iv depends on algorithm you chose) in CTR mode
1
{ "version": 1 , "algorithm":"block flavor" , "type":"string", "plaintext": "your string", "hex":BOOL,
2
"operation":"enc", "key":"Hex stringsize=32-64","iv":"Hex stringsize=16-32", "mode":"ctr"}
Copied!
Json to dec string (key and iv depends on algorithm you chose) in CTR mode
1
{ "version": 1 , "algorithm":"block flavor" , "type":"string", "plaintext": "your hex enc string ",
2
"operation":"dec", "key":"Hex stringsize=32-64","iv":"Hex stringsize=16-32", "mode":"ctr"}
Copied!
  • To enc/dec a file you need to change "type":"string" -> "type":"file" , "plaintext": "your hex enc string " -> "file":"your file"
  • To use enc/dec GCM mode you need to change "mode":"ctr"->"mode":"gcm" , add "adata":"your string" and "hex" parameters
  • "hex" parameter apply for "string" and "adata" parameter
Last modified 9mo ago