Hello Freedom
This commit is contained in:
98
infidel-code/py_wrappers/Publish_Encrypted.py
Normal file
98
infidel-code/py_wrappers/Publish_Encrypted.py
Normal file
@@ -0,0 +1,98 @@
|
||||
import paho.mqtt.client as paho
|
||||
# from simplecrypt import encrypt, decrypt
|
||||
import base64
|
||||
from ctypes import *
|
||||
import _ctypes
|
||||
from textwrap import wrap
|
||||
|
||||
|
||||
# Konfigurasi MQTT server
|
||||
# broker = "192.168.43.134"
|
||||
broker = "nnag.xyz"
|
||||
client = paho.Client()
|
||||
port = 1883
|
||||
|
||||
def u_encrypt(arg):
|
||||
so_file = 'EES401/URG_encrypt.so'
|
||||
u_enc = CDLL(so_file)
|
||||
u_enc.main.restype = c_double
|
||||
u_enc.main.argtype = c_char_p
|
||||
str_temp = "07"
|
||||
c_return = u_enc.main(arg.encode('utf-8'), str_temp.encode('utf-8'))
|
||||
print("Python Log : C Return ", c_return)
|
||||
_ctypes.dlclose(u_enc._handle)
|
||||
|
||||
def u_decrypt(arg):
|
||||
# arg = base64.b64decode(arg)
|
||||
so_file2 = './URG_decrypt.so'
|
||||
arg_len = len(arg)
|
||||
arg = c_char_p(arg)
|
||||
print("Python Log : Current Cipher ", arg)
|
||||
print("Python Log : Length to be Dec ", arg_len)
|
||||
u_dec = CDLL(so_file2)
|
||||
u_dec.main.restype = c_char_p
|
||||
u_dec.main.argtype = c_char_p
|
||||
c_return = u_dec.main(arg)
|
||||
_ctypes.dlclose(u_dec._handle)
|
||||
return c_return
|
||||
|
||||
def file_handler(f_name, num):
|
||||
num = str(num).zfill(2)
|
||||
f = open("./cipher/"+f_name+"_"+num+".dat", "rb")
|
||||
return f.read()
|
||||
|
||||
# Proses enkripsi
|
||||
def payload_process(plain):
|
||||
u_encrypt(plain)
|
||||
plain = file_handler("cipher_EES401", 7)
|
||||
print("Python LOG Cipher Length : ", len(plain))
|
||||
send_data = base64.b64encode(plain)
|
||||
return send_data
|
||||
|
||||
def plain_handler(f_name, num):
|
||||
num = str(num).zfill(2)
|
||||
f = open("./plain/"+f_name+"_"+num+".txt", "r")
|
||||
return f.read()
|
||||
|
||||
|
||||
# Add this to test the Blacklist feature
|
||||
# blacklist_trigger = base64.b64encode(b"I'm gonna make this program crash!"*10)
|
||||
# cipher_arr.append(blacklist_trigger)
|
||||
# msg_data = blacklist_trigger
|
||||
|
||||
# ======================== || START FROM HERE BUDDY || ==================
|
||||
n = input("Enter number of plain : ")
|
||||
n = int(n)
|
||||
for i in range(1, n+1):
|
||||
plain = plain_handler("plain", i)
|
||||
i = 0
|
||||
my_ip = "device01"
|
||||
identifier = "&"
|
||||
f_name = "cipher_EES401"
|
||||
plain_arr = []
|
||||
cipher_arr = []
|
||||
# plain = input("Enter plain : ")
|
||||
# plain = "This message is longer than 4 char"
|
||||
x = 16 - (len(plain) % 4)
|
||||
plain = plain+(" "*x)
|
||||
plain_arr = wrap(plain, 16, replace_whitespace=False, drop_whitespace=False)
|
||||
print("Join List Test ", ''.join(plain_arr))
|
||||
client.connect(broker,port)
|
||||
# plain_now = plain_arr[1]
|
||||
|
||||
for i in range(len(plain_arr)):
|
||||
data_now = payload_process(plain_arr[i])
|
||||
cipher_arr.append(data_now)
|
||||
print("Plain now : ", plain)
|
||||
|
||||
msg_data = b''.join(cipher_arr)
|
||||
# send_data = my_ip+identifier+msg_data.decode('ascii')
|
||||
send_data = msg_data.decode('ascii')
|
||||
# print("Python LOG Plain : ", plain)
|
||||
print("Python LOG Plain Length : ", len(plain))
|
||||
print("Sending Cipher with length ", len(send_data))
|
||||
print("Python LOG Plain Array : ", plain_arr)
|
||||
# print("Python LOG Cipher Length : ", len(send_data))
|
||||
client.publish("device01/msg", send_data)
|
||||
# test_str = "Test String"
|
||||
# client.publish("device01/msg", base64.b64encode(test_str.encode("utf-8")) )
|
||||
Reference in New Issue
Block a user