def binaryConverter(self): _bin = Binary() binary = int(raw_input(" Binary : ")) decimal = _bin.toDecimal(binary) octal = _bin.toOctal(binary) hexadecimal = _bin.toHexadecimal(binary) print " Decimal : %d" % decimal print " Octal : %d" % octal print " Hexadecimal : %s" % hexadecimal
def testMagicNum(): print("Magic Number, Binary result, Input string") for string in ["testing","test","toast","bad","bbd","abcdef","abcdeg","abcdefg", "aaaaaaaaaa","aaaaaaaaaaa","testlongerstring","does this change anything?", "N0wI@mU$ing@l0t0F$ymbOlz"]: result = getMagicNumber(Binary(string.encode())) print(str(result) + " " + str(Binary(result,False,8)) + " " + string) print("defferent seeds: ") for seed in [1,2,3,4,5,6,64,139,218,365,720,420,76]: #internally mods 256 result = getMagicNumber(Binary("test".encode()),seed) print(str(result) + " " + str(Binary(result,False,8)) + " test")
def testResize(): #underlying code tested in testInitWithBin print("Resize") print(Binary('0b1001').resized(5).toBin() == '0b01001') print(Binary('0b1001', True).resized(5).toBin() == '0b11001') try: Binary('0b1001').resized(3) print(False) except Exception: print(True) print(Binary('0b1001').resized(3, True) == "0b001")
def readBinary(self, run, dataFormat="compressed"): binaryReader = Binary.BinaryReader() binaryReader.open(self.filename) #binaryReader.readOld(run) #binaryReader.readCompressed(run) binaryReader.formats[dataFormat](run)
def testOneToOne(): results = [] bad = [] good = [] for value in range(0,256): results.append(TestingAlgorithm(value)) for value in range(0,256): if value not in results: bad.append(value) else: good.append(value) print("bad: ") for item in bad: print(str(item) + " " + str(Binary(item))) print("good: ") for item in good: print(str(item) + " " + str(Binary(item))) print ("total bad: " + str(len(bad)))
def testSignChange(): #underlying code tested in testInitWithBin print("Sign Change") print(int(Binary(18).signed()) == -14) print(int(Binary(-18).signed()) == -18) print(int(Binary(18, True).unsigned()) == 18) print(int(Binary(-18, True).unsigned()) == 46) print(Binary('0b1001').signed().toBin() == '0b1001') print(Binary('0b1001', True).unsigned().toBin() == '0b1001') print(Binary(None, False).signed().isSigned) print(Binary(None, True).unsigned().isSigned == False)
def startCoding(): try: inputFile = open(sourceFileName.get(), "rb") outputFile = open(destFileName.get(), "wb") inputString = inputFile.read() print inputString code = "" #Encode the text if(selectionVar.get()==0): for letter in inputString: code += tree.codeLookUp[letter] hexValue = Binary.BinToHex(code) if((len(hexValue)%2)!=0): hexValue+="0" #I am using binascii because Binary.func() only deals with strings. I needed binascii to make actual hex types outputFile.write(binascii.a2b_hex(hexValue)) fileResult.set("The file was successfully encoded and should contain the hex value: " + hexValue) else: binVal = Binary.HexToBin(binascii.b2a_hex(inputString)) node = tree.nodeList[0] text = "" for base in binVal: #The if statements are far less then ideal, but for the sake of readability, I left them. if(base == "0"): node = node.left if(base == "1"): node = node.right if(node.value != None): text += node.value node = tree.nodeList[0] outputFile.write(text) fileResult.set("The file was successfully decoded and should contain the text: " + text) print "Success" inputFile.close() outputFile.close() except IOError: inputFile.close() outputFile.close() fileResult.set("File IO Error. Please select new/different files") print "One or more files could not be opened"
def makeGreyOrBinary(): if imageTypeValue == 2: #greyscale (Otsu's) print("greyscale") elif imageTypeValue == 1: binaryObj = Binary.Binary() histogram = binaryObj.compute_histogram(inputImage) optThreshold = binaryObj.find_optimal_threshold(histogram, inputImage) returnImage = binaryObj.binarize(inputImage, optThreshold) return returnImage
def testBytes(): print("Bytes") print(Binary("test".encode()).toBytes() == b'test') print(bytes(Binary(5, True)) == b'\x05') print(bytes(Binary(-5, True)) == b'\x0b') print(bytes(Binary(5, True, 20)) == b'\x00\x00\x05') print(bytes(Binary(-5, True, 20)) == b'\x0f\xff\xfb') print(bytes(Binary(0)) == b'\x00') #I shoved bool in here too print(bool(Binary(5, True))) print(bool(Binary(-5, True))) print(not bool(Binary(0))) try: bytes(Binary()) print(False) except Exception: print(True)
def testPut(): print("Put") print(Binary('0b1001').putBefore('0b0110').toBin() == '0b10010110') print(Binary('0b1001').putAfter('0b0110').toBin() == '0b01101001') print((Binary('0b1110', True) // Binary('0b0000')).toBin() == '0b11100000') print(Binary().putAfter('0b0110').toBin() == '0b0110') print(Binary().putBefore('0b0110').toBin() == '0b0110')
def testUnsigned(): print("To Unsigned Int") print(Binary("0b1111", True).toUint() == 15) print(Binary("0b1111").toUint() == 15) print(Binary(64).toUint() == 64) print(Binary(-64, True).toUint() == 64) print(Binary(-64).toUint() == 64) print(Binary(-7, True).toUint() == 9)
def testEmpty(): print("Empty") for function in [ '__add__', '__and__', '__eq__', '__ge__', '__gt__', '__le__', '__lt__', '__mul__', '__ne__', '__or__', '__sub__', '__xor__' ]: try: getattr(Binary(), function)(Binary(4)) print(False) except Exception: print(True) try: getattr(Binary(4), function)(Binary()) print(False) except Exception: print(True) for function in ['__invert__', '__neg__', '__pos__']: try: getattr(Binary(), function)() print(False) except Exception: print(True)
def main(): """The main function that parses input args, calls any of the morphological operations""" #parse input arguments #might change with gui implementation from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument("-i", "--image", dest="image", help="specify the name of the image", metavar="IMAGE") parser.add_argument("-t", "--threshold_type", dest="threshold", help="specify if wish to use otsu as thresholding operation", metavar="THRESHOLD TYPE") parser.add_argument("-o", "--operation", dest="operaton", help="specify which operation should be performed on binary image", metavar="OPERATION") args = parser.parse_args() #Load image if args.image is None: print("Please specify the name of image") print("use the -h option to see usage information") sys.exit(2) else: image_name = args.image.split(".")[0] input_image = cv2.imread(args.image, 0) #check if otsu thresholding is requested if args.threshold is None: print("Using normal threshold for binary") threshold = 'normal' else: threshold = args.mask bin_img_obj = bi.Binary() otsu_img_obj = mono.Monochrome() if threshold in ['normal']: hist = bin_img_obj.compute_histogram(input_image) threshold_value = bin_img_obj.find_optimal_threshold(hist,input_image) binary_image = bin_img_obj.binarize(input_image,threshold_value) else: hist = otsu_img_obj.compute_histogram(input_image)
def testHex(): print("Hex") print(Binary(5, True).toHex() == '0x5') print(Binary(-5, True).toHex() == '0xb') print(Binary(5, True, 20).toHex() == '0x00005') print(Binary(-5, True, 20).toHex() == '0xffffb') print(Binary(0).toHex() == '0x0') try: Binary().toHex() print(False) except Exception: print(True)
def testBinaryInit(): print("Init") print(Binary(20).toBin() == "0b10100") print(int(Binary(20)) == 20) print(Binary(-5).toBin() == "0b1011") print(int(Binary(-5)) == 11) print(Binary("0b111").toBin() == "0b111") print(int(Binary("0b111")) == 7) print(Binary("0x10").toBin() == "0b00010000") print(int(Binary("0x10")) == 16) print(Binary("0o13").toBin() == "0b001011") print(int(Binary("0o13")) == 11) print( Binary("test".encode()).toBin() == "0b01110100011001010111001101110100") print(Binary(20, True).toBin() == "0b010100") print(int(Binary(20, True)) == 20) print(Binary(-5, True).toBin() == "0b1011") print(int(Binary(-5, True)) == -5) print(Binary("0b111", True).toBin() == "0b111") print(int(Binary("0b111", True)) == -1) print(Binary("0xd", True).toBin() == "0b1101") print(int(Binary("0xd", True)) == -3) print(Binary("0o4", True).toBin() == "0b100") print(int(Binary("0o4", True)) == -4) print( Binary("test".encode(), True).toBin() == "0b01110100011001010111001101110100") print(Binary(20, False, 16).toBin() == "0b0000000000010100") print(int(Binary(20, False, 16)) == 20) print(Binary(-5, False, 16).toBin() == "0b1111111111111011") print(int(Binary(-5, False, 16)) == 65531) print(Binary("0b111", False, 16).toBin() == "0b0000000000000111") print(int(Binary("0b111", False, 16)) == 7) print(Binary("0xd", False, 16).toBin() == "0b0000000000001101") print(int(Binary("0xd", False, 16)) == 13) print(Binary("0o4", False, 16).toBin() == "0b0000000000000100") print(int(Binary("0o4", False, 16)) == 4) print( Binary("test".encode(), False, 48).toBin() == "0b000000000000000001110100011001010111001101110100") print(Binary(20, True, 16).toBin() == "0b0000000000010100") print(int(Binary(20, True, 16)) == 20) print(Binary(-5, True, 16).toBin() == "0b1111111111111011") print(int(Binary(-5, True, 16)) == -5) print(Binary("0b111", True, 16).toBin() == "0b1111111111111111") print(int(Binary("0b111", True, 16)) == -1) print(Binary("0xd", True, 16).toBin() == "0b1111111111111101") print(int(Binary("0xd", True, 16)) == -3) print(Binary("0o4", True, 16).toBin() == "0b1111111111111100") print(int(Binary("0o4", True, 16)) == -4) print( Binary("test".encode(), True, 48).toBin() == "0b000000000000000001110100011001010111001101110100") print(Binary().toBin() == '0b') print(Binary(None, True, 10).toBin() == '0b')
def all_encoding_stats(file_name="cyphesis_atlas_XML_2000-03-27.log"): """output with default file_name: Test file: cyphesis_atlas_XML_2000-03-27.log Msg count: 216 XML: Total length: 306086, Length/msg: 1417.1 gzip -9 compressed file: Total length: 12199, Length/msg: 56.5 bzip2 -9 compressed file: Total length: 7561, Length/msg: 35.0 PASCII: Total length: 85472, Length/msg: 395.7 gzip -9 compressed file: Total length: 8066, Length/msg: 37.3 bzip2 -9 compressed file: Total length: 6626, Length/msg: 30.7 BINARY1: Total length: 83980, Length/msg: 388.8 gzip -9 compressed file: Total length: 8373, Length/msg: 38.8 bzip2 -9 compressed file: Total length: 7204, Length/msg: 33.4 BINARY2: Total length: 57110, Length/msg: 264.4 gzip -9 compressed file: Total length: 7868, Length/msg: 36.4 bzip2 -9 compressed file: Total length: 6906, Length/msg: 32.0 BINARY3: Total length: 43997, Length/msg: 203.7 gzip -9 compressed file: Total length: 8315, Length/msg: 38.5 bzip2 -9 compressed file: Total length: 7692, Length/msg: 35.6 Test file: CyphesisClient_fromServerViewpoint2.log Msg count: 715 XML: Total length: 960968, Length/msg: 1344.0 gzip -9 compressed file: Total length: 25651, Length/msg: 35.9 bzip2 -9 compressed file: Total length: 13748, Length/msg: 19.2 PASCII: Total length: 200676, Length/msg: 280.7 gzip -9 compressed file: Total length: 17605, Length/msg: 24.6 bzip2 -9 compressed file: Total length: 13013, Length/msg: 18.2 BINARY1: Total length: 206101, Length/msg: 288.3 gzip -9 compressed file: Total length: 21787, Length/msg: 30.5 bzip2 -9 compressed file: Total length: 17140, Length/msg: 24.0 BINARY2: Total length: 131842, Length/msg: 184.4 gzip -9 compressed file: Total length: 20528, Length/msg: 28.7 bzip2 -9 compressed file: Total length: 16908, Length/msg: 23.6 BINARY3: Total length: 152391, Length/msg: 213.1 gzip -9 compressed file: Total length: 21779, Length/msg: 30.5 bzip2 -9 compressed file: Total length: 17905, Length/msg: 25.0 """ global all_msg all = open(file_name).read() msg_strings = re.split("<!-- .*?: -->", all)[1:] all_msg = map(atlas.XML2Object, msg_strings) print "Test file:", file_name print "Msg count:", len(all_msg) #XML size xml = atlas.XMLProtocol() codec = atlas.Codec(xml) calculate_stats(all_msg, codec.encodeMessage, "XML") #PASCII size pascii = atlas.PackedProtocol() codec = atlas.Codec(pascii) calculate_stats(all_msg, codec.encodeMessage, "PASCII") #BINARYX size for i in [1, 2, 3]: binary_codec = Binary(i) calculate_stats(all_msg, binary_codec.encode, "BINARY%i" % i)
<list name="args"> <map> <string name="message">Account id already exist</string> </map> <map> <string name="abstract_type">operation</string> <list name="parent"> <string>create</string> </list> <int name="serialno">1</int> <map name="time"> <float name="seconds">19035676005.9</float> <string name="time_string">0612-01-01 07:46:45.9</string> </map> <list name="args"> <map> <string name="password">lZYVYjmU</string> <string name="id">admin</string> <list name="parent"> <string>player</string> </list> </map> </list> </map> </list> </map> </obj> """) b = Binary(3)
def ip_finder(x,y): IP=[] IP=x.split(".") Mask=int(y) bits=[] for i in range(7,-1,-1): bits.append(2**i) mask_decimal=[] number=0 cont=Mask for i in range(0,4): for i in range(0,cont): number=bits[i]+number #print("Number {}, i {}".format(number,i)) if i>=7: break mask_decimal.append(number) cont=cont-8 number=0 mask_binary=[] for i in range(4): mask_binary.append(Binary.decimal_to_binary(mask_decimal[i])) wildcard_decimal=[] # Saber en que posicion comienzan los ceros Wildcard=32-Mask # Wildcard cont=Wildcard wildcard_bits=bits[::-1] for i in range(0,4): for i in range(0,cont): number=wildcard_bits[i]+number #print("Number {}, i {}".format(number,i)) if i>=7: break wildcard_decimal.append(number) cont=cont-8 number=0 wildcard_decimal=wildcard_decimal[::-1] net_address=[0,0,0,0] net_address_binary=[] byte=int(Mask/8) position=Mask-(byte*8) #User per net flag=0 user_available=0 for i in range(4): if (wildcard_decimal[i]!=0 and flag==0): print(wildcard_decimal[i],flag) user_available=wildcard_decimal[i]+1 flag=1 else: user_available=user_available*(wildcard_decimal[i]+1) user_available=user_available-2 # Net Address IP_binary=Binary.decimal_to_binary(int(IP[byte])) net_address_binary=IP_binary for i in range(8): if i>=position: net_address_binary[i]=0 net_address=IP net_address[byte]=str(Binary.binary_to_decimal(net_address_binary)) for i in range(byte+1,4): net_address[i]=0 # Final mask_complete=" " wildcard_complete=" " net_address_complete=" " mask_complete=str(mask_decimal[0])+"."+str(mask_decimal[1])+"."+str(mask_decimal[2])+"."+str(mask_decimal[3]) wildcard_complete=str(wildcard_decimal[0])+"."+str(wildcard_decimal[1])+"."+str(wildcard_decimal[2])+"."+str(wildcard_decimal[3]) net_address_complete=str(net_address[0])+"."+str(net_address[1])+"."+str(net_address[2])+"."+str(net_address[3]) ip_info=[] ip_info.append(mask_complete) ip_info.append(wildcard_complete) ip_info.append(net_address_complete) print("Mascara de red \t {} \n Wildcard \t {} \n Net Address \t {} \n".format(mask_complete,wildcard_complete,net_address_complete))
import loopy ### REF: https://stackabuse.com/search-algorithms-in-python/#fibonaccisearch dic = Payload.RandomString() search = 'KEQw6KGtxx685L09W4lo' ################################## ### Binary Search start = time.time() # # Algorithem starts here x = Binary.Search(dic , search) print("Binary Search Result: " + str(x)) # # Algoritem stops here end = time.time() print("Binary Search Time: " + str(end-start)) print() ################################## ### Jump Search start = time.time() # # Algorithem starts here x = Jump.Search(dic , search) print("Jump Search Result: " + str(x)) # # Algoritem stops here end = time.time() print("Jump Search Time: " + str(end-start))
def testInitWithBin(): print("Initializing with binary") print(Binary(Binary(10), False, 6).toBin() == "0b001010") print(int(Binary(Binary(10), False, 6)) == 10) print(Binary(Binary(-10, True), True, 6).toBin() == "0b110110") print(int(Binary(Binary(-10, True), True, 6)) == -10) try: Binary(Binary(10), False, 2) print(False) except Exception: print(True) print(Binary(Binary(10, True), False).toBin() == "0b01010") #sign bit maintained with length print(Binary(Binary(-10), True) == "0b10110") print(Binary(Binary(-10), True) == -10) print(Binary(Binary(0, True), False, 10).toBin() == "0b0000000000") print(Binary(Binary(-12), True, 10).toBin() == "0b1111110100") print(Binary(Binary(), True).toBin() == '0b')
# Check if the croped image has shadows or something else that might # hinder the egg recognition if Defects.shadow_index(im) > 0.13: print(IO.json_packing_error('ERR_004')) exit() # Removing unused regions outer of pallete's borders im = Utils.remove_background(im) # improve contrast among the objects and palette im = Utils.adjust_contrast(im) print("\nPerforming segmentation...\n") # First step: quantization by clusterization to reduce the amount of colors bimage = Binary.im_threshold(Clusterization.im_quantization(im, 3)) # extracting the features... # ============================================================== SIZE # get perimeter of everything is in the image tinf = [0.10, 0.35] tsup = [0.10, 0.50] print("Peforming classification by size...") # First classification by area. This method aims to classify the objects by its area # Next, the clusters pixels are going to be labeled by color. areas_eggs, areas_clusters = Classification.classification_by_area_lenght( detect.object_detection(bimage), params[2], tinf)
import Golden import Binary ak = int(input("最小值:")) bk = int(input("最大值:")) L = [1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, 1e-8] B = [] B_Value = [] G = [] G_Value = [] F = [] F_Value = [] for i in L: b_value, b = Binary.BinarySearch(ak, bk, i) g_value, g = Golden.GoldenSearch(ak, bk, i) f_value, f = Fibonacci.FibonacciSearch(ak, bk, i) B.append(b) B_Value.append(b_value) G.append(g) G_Value.append(g_value) F.append(f) F_Value.append(f_value) plt.figure(figsize=(12, 8), dpi=80) plt.figure(1) ax1 = plt.subplot(321) plt.plot(L, B, "or") #color='#FF0000' ax2 = plt.subplot(322)
def testCompare(): print("Compare") print(Binary(5) == 5) print(Binary(-4, True) == -4) print(Binary(-4) != -4) print(Binary(-15, True, 10) == Binary(-15, True, 10)) print(Binary(-15, True, 10) != Binary(-15, False, 10)) print(Binary(-15, True, 20) != Binary(-15, True, 10)) print(Binary(-15, False, 20) != Binary(-15, False, 10)) print(Binary("0b1001", False) != Binary("0b1001", True)) print(Binary(10) < Binary(20)) print(Binary(10, True) < Binary(20, True)) print(Binary(-5) > Binary(3)) #unsigned print(Binary(-10, True) > Binary(-20, True)) print(Binary(5) <= 6) print(Binary(5) <= 5) print(Binary(5) >= 5) print(Binary(5) >= 4) print(not Binary(5) == 4) print(not Binary(-4) == -4) print(not Binary("0b1001", True) != Binary("0b1001", True)) print(not Binary(10) > Binary(20)) print(not Binary(10, True) > Binary(20, True)) print(not Binary(-5) < Binary(3)) #unsigned print(not Binary(-10, True) < Binary(-20, True)) print(not Binary(5) >= 6) print(not Binary(5) != 5) print(not Binary(5) <= 4)
def testShift(): print("Shift") print(Binary("0b1100").shifted(1, "left", "barrel").toBin() == "0b1001") print(int(Binary("0b1100", False).shifted(1, "left", "barrel")) == 9) print(int(Binary("0b1100", True).shifted(1, "left", "barrel")) == -7) print(Binary("0b1100").shifted(1, "left").toBin() == "0b11000") print(Binary("0b1100").shifted(1, "right", "barrel").toBin() == "0b0110") print(Binary("0b1100").shifted(1, "right").toBin() == "0b0110") print( Binary("0b1100").shifted(1, "right", "arithmetic").toBin() == "0b1110") print(Binary("0b1100").shifted(3, "left", "barrel").toBin() == "0b0110") print(Binary("0b1100").shifted(3, "left").toBin() == "0b1100000") print(Binary("0b1100").shifted(3, "right", "barrel").toBin() == "0b1001") print(Binary("0b1100").shifted(3, "right").toBin() == "0b0001") print( Binary("0b1100").shifted(3, "right", "arithmetic").toBin() == "0b1111") print(Binary("0b1100").shifted(50, "left", "barrel").toBin() == "0b0011") print( Binary("0b1100").shifted(50, "left").toBin() == "0b110000000000000000000000000000000000000000000000000000") print(Binary("0b1100").shifted(50, "right", "barrel").toBin() == "0b0011") print(Binary("0b1100").shifted(50, "right").toBin() == "0b0000") print( Binary("0b1100").shifted(50, "right", "arithmetic").toBin() == "0b1111") print((Binary("0b1010") << 5).toBin() == "0b101000000") print((Binary("0b10101110") >> 3).toBin() == "0b00010101") print((Binary("0b10101110", True) >> 3).toBin() == "0b11110101") try: Binary() << 2 print(False) except Exception: print(True) try: Binary() >> 2 print(False) except Exception: print(True)
def testBitwise(): print("Bitwise") #not print((~Binary("0b10011001")).toBin() == "0b01100110") print((~Binary("0b01100110")).toBin() == "0b10011001") print((~Binary("0b10011001", True)).toBin() == "0b01100110") print((~Binary("0b01100110", True)).toBin() == "0b10011001") print(~Binary(0) == "1") print(int(~Binary(0)) == 1) print(int(~Binary(0, True)) == -1) print( (Binary("0b0000000011111111") & Binary("0b1001001110010011")).toBin() == "0b0000000010010011") #and print( (Binary("0b0000000011111111") | Binary("0b1001001110010011")).toBin() == "0b1001001111111111") #or print( (Binary("0b0000000011111111") ^ Binary("0b1001001110010011")).toBin() == "0b1001001101101100") #xor print( (Binary("0b110000", True) & Binary("0b1001001110010011")).toBin() == "0b1001001110010000") #and print((Binary("0b1001001110010011") & Binary("0b110000", True)).toBin() == "0b1001001110010000") #and print( (Binary("0b110000", True) | Binary("0b1001001110010011")).toBin() == "0b1111111111110011") #or print((Binary("0b1001001110010011") | Binary("0b110000", True)).toBin() == "0b1111111111110011") #or print( (Binary("0b110000", True) ^ Binary("0b1001001110010011")).toBin() == "0b0110110001100011") #xor print((Binary("0b1001001110010011") ^ Binary("0b110000", True)).toBin() == "0b0110110001100011") #xor print(int(Binary(-1, True) & 12) == -4) #sign retained print(int(Binary(-1) & 12) == 0) print(int(Binary(12) & -1) == 12) print((Binary(12, True) & -1) == '0b01100') print((Binary(12, True) | -1) == '0b11111') print(int(Binary(12, True) & -1) == 12) print(int(Binary(12, True) | -1) == -1)
def operate(key, debug=False): l = len(codes[key]) n1 = codes[key][l-1] n2 = 0 #print("Key:", key, "n1:", n1) try: codes[key][l-1] = float(codes[key][l-1]) n1 = codes[key][l-1] #n1 = float(n1) except ValueError: codes[key][l-1] = operate(codes[key][l-1], debug) n1 = codes[key][l-1] #n1 = operate(n1) except: print("Uncaught Exception at n1") if l == 1: return n1 elif l == 2: return b.toDenary(b.complement(n1)) elif l == 3: try: codes[key][0] = float(codes[key][0]) n2 = codes[key][0] #n2 = float(n2) except ValueError: codes[key][0] = operate(codes[key][0], debug) n2 = codes[key][0] #n2 = operate(n2, debug) except: print("Uncaught exception at n2!") else: print("Unhandled Length") #print("Calculation\nKey:", key, "n1:", n1, "n2:", n2, "\n") #print(codes[key]) if codes[key][1] == "OR": if debug == True: print("OR", key, codes[key], n1, n2, b.toDenary(b.bitwiseOR(n2,n1))) return b.toDenary(b.bitwiseOR(n2,n1)) elif codes[key][1] == "AND": if debug == True: print("AND", key, codes[key], n1, n2, b.toDenary(b.bitwiseAND(n2,n1))) return b.toDenary(b.bitwiseAND(n2,n1)) elif codes[key][1] == "LSHIFT": if debug == True: print("LSHIFT", key, codes[key], n1, n2, b.leftShift(n2,n1)) return b.leftShift(n2,n1) elif codes[key][1] == "RSHIFT": if debug == True: print("RSHIFT", key, codes[key], n1, n2, b.rightShift(n2,n1)) return b.rightShift(n2,n1) else: print("Bad Operator for l=3")
""" Created on Sun Feb 17 15:00:52 2019 @author: marti """ from Orbit import * from Binary import * import matplotlib.pyplot as plt import numpy as np import matplotlib.animation N = 2000000 orbit1 = Orbit.Orbit(N, 0.01, 1, [20, 0.], [0.1, 0.1]) orbit2 = Orbit.Orbit(N, 0.1, 1., [-20, 0.], [-0.1, -0.1]) binarytest = Binary(orbit1, orbit2) binarytest.compute() binarytest.visualize() plt.show() fig = plt.figure() ax = plt.axes(xlim=(0, 2), ylim=(-2, 2)) line, = ax.plot([], [], lw=2) # initialization function: plot the background of each frame def init(): line.set_data([], []) return line, # animation function. This is called sequentially
def testInsertRemove(): print(Binary('0b10000001').inserted('0b11', 4) == Binary('0b1000110001')) print(Binary('0b10000001').inserted('0b11', 0) == Binary('0b1110000001')) print(Binary('0b10000001').inserted('0b11', 8) == Binary('0b1000000111')) print(Binary('0b10101010').removed(0) == Binary('0b0101010')) print(Binary('0b10101010').removed(4) == Binary('0b1010010')) print(Binary('0b10101010').removed(7) == Binary('0b1010101'))
def testIndexing(): print("Indexing") print(Binary("0b1010111")[0] == "0b1") print(Binary("0b1010111")[1:3] == "0b01") print(Binary("0b1010111")[3:] == Binary("0b0111")) print(Binary("0b1010111")[:] == Binary("0b1010111")) print( list(iter(Binary("0b1010111"))) == ["1", "0", "1", "0", "1", "1", "1"]) print( list(reversed(Binary("0b1010111"))) == ["1", "1", "1", "0", "1", "0", "1"]) print("0b1010" in Binary("0b1010111")) print("0b1010" not in Binary(0)) print(Binary("0b1111") in Binary("0x8f")) print(list(iter(Binary()))[0].data is None) print(list(reversed(Binary()))[0].data is None) print(Binary() not in Binary(4)) print(Binary() not in Binary()) print("4" not in Binary()) print(list(iter(Binary()))[0].data is None)
def testObfuscate(): for string in ["testing","test","toast","bad","bbd","abcdef","abcdeg","abcdefg", "aaaaaaaaaa","aaaaaaaaaaa","testlongerstring","does this change anything?", "N0wI@mU$ing@l0t0F$ymbOlz"]: result = obfuscate(Binary(string.encode())) print(string + " " + result.toBytes().decode("Latin-1") + " " + Binary(string.encode(),False).toHex() + " " + Binary(result,False).toHex())
#!/usr/bin/env python import Caesar import Binary userinput = raw_input() print "user input: " + userinput encr = Caesar.rotate(userinput, 13) decr = Caesar.rotate(encr, 13) print Binary.shortdecode(userinput) print encr print decr