''' Extracting code ''' StegoFile = open('Stego.txt', 'r') StegoLength = StegoFile.read() StegoFile.close() print("# Character after hiding (Stego Length) = ", len(StegoLength)) StegoList = [] StegoTemp = [] ReadChar = 0 StegoFile = open('Stego.txt', 'r') #Read Stego text and convert it to hex strings while ReadChar < len(StegoLength): StegoChar = StegoFile.read(1) StegoTemp.append(''.join([f'\\u{ord(StegoChar):0>4x}'])) StegoList.append(StegoTemp[ReadChar].replace('\\u','0x')) ReadChar += 1 StegoFile.close() StegoText = [] StegoXor = [] Extracted = [] #Extract the Xor bits corresponding to secret bits i = 0 W_Count = 0 C_Count = 0 while (StegoList[i] != '0xfe00') and (StegoList[i] != '0xfe01'): # check for the end of secret bits if (StegoList[i]) == '0x061c': StegoXor.append(0) StegoXor.append(0) W_Count += 1 elif (StegoList[i]) == '0x200f': StegoXor.append(0) StegoXor.append(1) W_Count += 1 elif (StegoList[i]) == '0x200c': StegoXor.append(1) StegoXor.append(0) W_Count += 1 elif (StegoList[i]) == '0x034f': StegoXor.append(1) StegoXor.append(1) W_Count += 1 elif (StegoList[i]) == '0x0020': if W_Count != C_Count: print("Text may be altered.") else: # print(W_Count, '=', C_Count) None C_Count = 0 W_Count = 0 else: StegoText.append(chr(int(StegoList[i], base = 16))) C_Count += 1 i += 1 LastChar = StegoList[i] #Extract secret bits by Xoring the corresponding letters j= 0 i = 0 while j < len(StegoXor): if StegoText[i] in ["ب" ,"ت" ,"ث","ج","خ","ذ","ز", "ش","ض","ظ","غ", "ف","ق", "ن","ي","ة"]: D = 1 # The letter is dotted else: D = 0 # The letter is undotted if StegoText[i] in ["أ" ,"ا" ,"آ","إ","د","ذ","ر", "ز","و","ؤ","ى","ة","ء"]: C = 0 # The letter is disconnected else: C = 1 # The letter is connected Extracted.append(D ^ StegoXor[j]) Extracted.append(C ^ StegoXor[j+1]) j += 2 i += 1 #Check if Extarced bits are the same as Secret bits if (Secret == Extracted): print("Successful Extraction") else: print("False Extarction") #Remove last bit if the number of secret bits is odd if LastChar == '0xfe00': k = len(Extracted)-1 Extracted.pop(k) print(Extracted) StegoFile.close()