def __init__(self, config, cons): assert config['bit_depth'] >= 1 assert config['pixels_per_cycle'] >= 1 self.bd = config['bit_depth'] self.ps = config['pixels_per_cycle'] self.axi_lite = config['support_axi_lite'] enc_out_bits = min(31, 16 + self.bd) * self.ps #pixels in self.pixels_in = Array( Signal(self.bd, name="pixel_in") for _ in range(self.ps)) #enc out self.enc_out = Signal(enc_out_bits) self.enc_out_ctr = Signal(max=enc_out_bits + 1) # valid in & out self.valid_in = Signal(1) self.valid_out = Signal(1) # end self.end_out = Signal(1) self.fend_out = Signal(1) if self.ps == 4: self.predictor = predictor_p1_c4_px4.PredictorP1C4Px4(config, cons) else: self.predictor = predictor_p1_c4_pix1_2.PredictorP1C4Pix12( config, cons) self.difference = difference.Difference(config, cons) self.normalize = normalize.Normalize(config, cons) self.encode = encode.Encode(config, cons) #create a merge layer only if more than one pixel per cycle if self.ps > 1: self.merge = merge.Merge(config, cons) self.signals = signals.Signals(config, cons) if self.axi_lite: self.core_axi_lite = core_axi_lite.CoreAxiLite(config, cons) else: self.register_file = register_file.RegisterFile() self.force_end = force_end.ForceEnd(config, cons) self.ios = \ [pixel_in for pixel_in in self.pixels_in] + \ [self.enc_out, self.enc_out_ctr] + \ [self.valid_in, self.valid_out] + \ [self.end_out, self.fend_out]
def EncodeMessage(): UserInputImage = input("Enter the name of the image in which you would like to encrypt your message (with extension): ") #image = Image.open(UserInputImage, 'r') SecretMessage = input("Enter the message you would like to encode : ") if (len(SecretMessage) == 0): raise ValueError('Message is empty') EncryptPasscode = input("Set a passcode for you to decrypt the message in future: ") print("Your secret message: '" + SecretMessage + "' is getting encoded in the image: '" + UserInputImage + "' . \nPlease use the passphrase: '" + EncryptPasscode + "' as a future reference to decode the message!" ) print ("Encoding your message") EncryptPasscode = " " + EncryptPasscode SecretMessage += EncryptPasscode # Encode the message into the image EncodeImage = encode.Encode(UserInputImage,SecretMessage) EncodeImage.hide_function()
def encode_image(image_path, password, text_to_encode): # calling Encode class constructor encode_action = encode.Encode(image_path, password, text_to_encode) # calling method inside Encode class to check if all the values are valid msg = encode_action.are_values_valid() # checking the status message returned by above function if not msg[1]: # showing error if the supplied values are invalid messagebox.showerror("Error Encoding", msg[0]) else: # calling a method inside Encode class to encode the data into image if all the values are valid stego_image = encode_action.encode_into_image() # checking the returned status message from the function above if stego_image[1]: # calling save_image() function to show the save image dialog and save the output image if save_image(stego_image[0]) is None: messagebox.showinfo("Image Saved", "Encode operation was successful.") else: # Showing error if any error occurs while encoding the image messagebox.showerror("Error Encoding", stego_image[0])
from PIL import Image import encode import decode conti = 1 while conti: k = input( "Press Key 1 : Encode \n 2 : Decode \n Other key : Exit\n") if k == '1': encode.Encode() elif k == '2': decode.Decode() else: break conti = input("Want to Encode/Decode again(y/n) : ") if conti.upper() == 'Y' or conti.upper() == 'YES': conti = 1 else: conti = 0
# Press ⌃R to execute it or replace it with your code. # Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings. import encode import decode def print_hi(name): # Use a breakpoint in the code line below to debug your script. print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint. # Press the green button in the gutter to run the script. if __name__ == '__main__': print_hi('PyCharm') i = 0 iteration_times = 100 dataNum = 5 # should not be to large, 20 might be too big, usually 5~10 dataMade = 3 # around dataNum/2 dataLost = 3 # must less or equal to dataMade while i < iteration_times: encoder = encode.Encode(dataNum, dataMade) encoder.encoding() checker = decode.Check(dataLost) lostRows = checker.make_lost(encoder) decoder = decode.Decode(lostRows) decoder.decoding(encoder, checker) print(i) i = i + 1
def __init__(self): self.e = encode.Encode() self.d = decode.Decode()