From d307dc2bd19acb7d8c214145b6fc97d2e417f391 Mon Sep 17 00:00:00 2001 From: Akshit Grover Date: Mon, 9 Oct 2017 14:27:38 +0530 Subject: [PATCH 1/7] Add Image Encoder --- README.md | 5 +++++ bin/ImageData/encodeData.json | 2 ++ bin/image_encoder.py | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 bin/ImageData/encodeData.json create mode 100644 bin/image_encoder.py diff --git a/README.md b/README.md index eed9cad..14ac60d 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,11 @@ Encrypts or Decrypts any message you want, simply enter the message and the rota ```bash python caesar_cipher.py ``` +### Image Encoder +It is a simple program to encode and decode images, which helps to reduce and handle images on server, as it is convertedto base64 address. +```bash +python image_encoder.py +``` ## Release History diff --git a/bin/ImageData/encodeData.json b/bin/ImageData/encodeData.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/bin/ImageData/encodeData.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/bin/image_encoder.py b/bin/image_encoder.py new file mode 100644 index 0000000..a03ec5f --- /dev/null +++ b/bin/image_encoder.py @@ -0,0 +1,25 @@ +import base64 +import json +import time + +def b64_encode(source_filepath): + with open(source_filepath, 'rb') as f: + data = f.read() + dest = open('ImageData/encodeData.json','r') + flag = json.loads(dest.read()) + key = (str(int(time.time()))).decode('utf-8') + d = {"data":base64.b64encode(data).decode('utf-8'),"ext":source_filepath[source_filepath.index('.'):]} + flag[key] = d + dest.close() + dest = open('ImageData/encodeData.json','w') + json.dump(flag,dest) + return key + +def b64_decode(key,dest_path): + source = open('ImageData/encodeData.json','r') + flag = json.loads(source.read()) + name = key+str(flag[key]["ext"]) + dest = open(dest_path+name,'wb') + dest.write(base64.b64decode((flag[key]["data"]).encode('utf-8'))) + dest.close() + return dest_path+name From 0de8b5e08a47ef32b6d5a76b45a3e92c3c84f5c4 Mon Sep 17 00:00:00 2001 From: Akshit Grover Date: Mon, 9 Oct 2017 14:51:49 +0530 Subject: [PATCH 2/7] Add Missionaries And Cannibals Problem --- README.md | 6 ++ bin/missionaries_and_cannibals_problem.py | 103 ++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 bin/missionaries_and_cannibals_problem.py diff --git a/README.md b/README.md index 14ac60d..650c6fc 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,12 @@ It is a simple program to encode and decode images, which helps to reduce and ha python image_encoder.py ``` +### Missionaires And Cannibals Problem +It is a simple program to mimic Missionaries And Cannibals River Crossing Problem. +```bash +python missionaries_and_cannibals_problem.py +``` + ## Release History * 0.0.1 diff --git a/bin/missionaries_and_cannibals_problem.py b/bin/missionaries_and_cannibals_problem.py new file mode 100644 index 0000000..bd51b91 --- /dev/null +++ b/bin/missionaries_and_cannibals_problem.py @@ -0,0 +1,103 @@ +shore = {1:['m1','m2','m3','c1','c2','c3'],2:[]} +boat = {1:True,2:False} +boat_cap = 0 +boat_hold = [] +choice = 'y' +count = 0 +glob = 1 +def pick(): + print("Pick a person to put on boat/or press enter") + return input() +def check(person,flag,avail_p): + if(person in shore[flag] or person == "" or person in boat_hold): + return True + else: + return False +def check_conditions(shore,flag,cflag,boatf): + num_m = 0 + num_c = 0 + true = 0 + for i in shore[flag]: + if(i[0] == 'm'): + num_m = num_m + 1 + else: + num_c = num_c + 1 + if(num_m < num_c and num_m > 0): + return False + else: + true = 1 + num_m = 0 + num_c = 0 + for i in shore[cflag]+boatf: + if(i[0] == 'm'): + num_m = num_m + 1 + else: + num_c = num_c + 1 + if(num_m < num_c and num_m > 0): + return False + elif(true == 1): + return true +while(choice == 'Y' or choice == 'y'): + count = 0 + win = 0 + while(count <= 25): + def again(shore,boat_hold): + print("People On Shore "+str(flag)+ " are: ") + print() + print(shore[flag] + boat_hold) + shore[flag] = shore[flag] + boat_hold + avail_p = shore[flag] + boat_hold + boat_hold =[] + for i in range(2): + print("For Person " + str(i+1)) + print() + person = pick() + if(i == 0 and person == ""): + while(person == ""): + print("Boat Cannot Be Empty") + person = pick() + if((not person == "") and person in avail_p): + boat_hold.append(person) + del avail_p[avail_p.index(person)] + del shore[flag][shore[flag].index(person)] + elif(person not in avail_p and not person == ""): + print("Invalid Choice") + person = pick() + while(not check(person,flag,avail_p)): + person = pick() + if(person == ""): + break + glob = 0 + return boat_hold + if(boat[1]): + flag = 1 + cflag = 2 + else: + flag = 2 + cflag = 1 + if(glob == 1): + boat_hold = again(shore,boat_hold) + while(not check_conditions(shore,flag,cflag,boat_hold)): + print() + print("** Invalid Move,Try Again **") + print() + boat_hold = again(shore,boat_hold) + print("Sending Boat") + print() + avail_p = shore[cflag] + boat_hold + boat[cflag] = True + boat[flag] = False + glob = 1 + if(len(shore[1]) == 0): + win = 1 + print("Congratulation, You Solved The Problem.") + break + count = count + 1 + if(win == 0): + print() + print("*** Sorry, Number of moves exceeeded ***") + print() + print("Do You Want To Replay? Y/N",end=" ") + choice = input() + + From d2896bc4fc8ac003ce0b765cc6355d43ba538895 Mon Sep 17 00:00:00 2001 From: Akshit Grover Date: Tue, 10 Oct 2017 20:59:09 +0530 Subject: [PATCH 3/7] Add Basic End-To-End Encryption --- README.md | 7 +++++++ bin/end_to_end.py | 39 +++++++++++++++++++++++++++++++++++++++ bin/server.txt | 1 + 3 files changed, 47 insertions(+) create mode 100644 bin/end_to_end.py create mode 100644 bin/server.txt diff --git a/README.md b/README.md index 650c6fc..3ece01f 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,13 @@ It is a simple program to mimic Missionaries And Cannibals River Crossing Proble python missionaries_and_cannibals_problem.py ``` +### End To End Encryption +It is a simple program to implement and understand the basic of end_to_end encryption. +Here i am using caesar cipher to encrpt nbut in reality they Use algotihms lile SHA-1, RSA etc. +```bash +python end_to_end.py +``` + ## Release History * 0.0.1 diff --git a/bin/end_to_end.py b/bin/end_to_end.py new file mode 100644 index 0000000..264ca3d --- /dev/null +++ b/bin/end_to_end.py @@ -0,0 +1,39 @@ +import time +a = ['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'] +def encrypt(msg): + off = 3 + enc = "" + for i in msg: + enc = enc + (a[(a.index(i)+off)%26]) + return enc +def decrypt(msg): + off = 3 + dec = "" + for i in msg: + dec = dec + (a[(a.index(i)-off)%26]) + return dec + +#Client Side(Sender) +msg = input("Enter Message To Send: ") +f = open('server.txt','w+') +print("Encrypting..........") +time.sleep(2) +enc = encrypt(msg) +print("Message Sent Is: ",enc) + +#Server Side +f.write(enc) +f.close() + +print() +#Client Side(Reciever) +print("Reciever Is Recieving.........") +time.sleep(2) +f = open('server.txt','r+') +msg = f.read() +print("Message Recieved Is: ",msg) +print("Decrypting........") +time.sleep(2) +dec = decrypt(msg) +print("Message Displayed Is: ",dec) + diff --git a/bin/server.txt b/bin/server.txt new file mode 100644 index 0000000..32eab29 --- /dev/null +++ b/bin/server.txt @@ -0,0 +1 @@ +dddvdvkegivmk \ No newline at end of file From a3569081df95153da6a876a72c3de20037441433 Mon Sep 17 00:00:00 2001 From: Akshit Grover Date: Wed, 11 Oct 2017 15:08:58 +0530 Subject: [PATCH 4/7] Add server_client.py --- README.md | 7 +++++++ bin/server_client/client.py | 16 ++++++++++++++++ bin/server_client/server.py | 14 ++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 bin/server_client/client.py create mode 100644 bin/server_client/server.py diff --git a/README.md b/README.md index 3ece01f..070b51b 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,13 @@ Here i am using caesar cipher to encrpt nbut in reality they Use algotihms lile python end_to_end.py ``` +### End To End Encryption +It is simple client server communication script, will add more functionality in future. +```bash +python client.py +python server.py +``` + ## Release History * 0.0.1 diff --git a/bin/server_client/client.py b/bin/server_client/client.py new file mode 100644 index 0000000..94f2654 --- /dev/null +++ b/bin/server_client/client.py @@ -0,0 +1,16 @@ +import sys +from socket import socket, AF_INET, SOCK_DGRAM, SOL_SOCKET, SO_REUSEADDR + +SERVER_IP = '127.0.0.1' +PORT_NUMBER = 5000 +SIZE = 1024 +print ("Test client sending packets to IP {0}, via port {1}\n".format(SERVER_IP,PORT_NUMBER)) + +mySocket = socket( SOCK_DGRAM ) +mySocket.connect((SERVER_IP,PORT_NUMBER)) + +while True: + data = mySocket.recv(SIZE) + print(data) +sys.exit() +mySocket.close() diff --git a/bin/server_client/server.py b/bin/server_client/server.py new file mode 100644 index 0000000..c02d6c4 --- /dev/null +++ b/bin/server_client/server.py @@ -0,0 +1,14 @@ +from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM, SOL_SOCKET, SO_REUSEADDR +import sys +PORT_NUMBER = 5000 +SIZE = 1024 + +hostName = gethostbyname( 'localhost' ) + +mySocket = socket( SOCK_DGRAM ) +mySocket.bind((hostName, PORT_NUMBER)) +mySocket.listen(1) +while True: + client, addr = mySocket.accept() + data = client.send("Connection Established: ") +sys.exit() From f8d811098d8ea3d1b1f22687fe4c14b36ffcb8e0 Mon Sep 17 00:00:00 2001 From: Akshit Grover Date: Wed, 11 Oct 2017 15:10:43 +0530 Subject: [PATCH 5/7] Update Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 234684b..b8d6083 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ Here i am using caesar cipher to encrpt nbut in reality they Use algotihms lile python end_to_end.py ``` -### End To End Encryption +### Server And Client It is simple client server communication script, will add more functionality in future. ```bash python client.py From b5469566631353616df7a318bbf5860890db6245 Mon Sep 17 00:00:00 2001 From: Akshit Grover Date: Wed, 11 Oct 2017 15:24:12 +0530 Subject: [PATCH 6/7] Update Readme.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b8d6083..a26379f 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,8 @@ python end_to_end.py ### Server And Client It is simple client server communication script, will add more functionality in future. ```bash +cd server_client + python client.py python server.py ``` From ce4d26b6cf0135290199f789e4b7c36ad9f32d79 Mon Sep 17 00:00:00 2001 From: Khushal Sharma Date: Wed, 11 Oct 2017 15:32:31 +0530 Subject: [PATCH 7/7] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 72cc0e9..5d41f7a 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,6 @@ python end_to_end.py It is simple client server communication script, will add more functionality in future. ```bash cd server_client - python client.py python server.py ```