當前位置: 首頁>>代碼示例>>Python>>正文


Python KNN.ibk方法代碼示例

本文整理匯總了Python中KNN.ibk方法的典型用法代碼示例。如果您正苦於以下問題:Python KNN.ibk方法的具體用法?Python KNN.ibk怎麽用?Python KNN.ibk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在KNN的用法示例。


在下文中一共展示了KNN.ibk方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import KNN [as 別名]
# 或者: from KNN import ibk [as 別名]
def main(argv):
    """ Start of the program """
    
    if len(argv)==0:      ## check of the arguments
        print("\n Improper command format")
        usage()
        sys.exit()
        
    filename=''  
    flow = False
    dump = False
    try:
        opts,args=getopt.getopt(argv,"hf:d",["ifile=", "dump"])   
    except getopt.GetoptError:
        print("\n Improper command format")
        usage()
        sys.exit()
        
    ## to read the arguments
    for opt,arg in opts:
        if opt=="-h":
            usage()
            sys.exit()
        elif opt in ("-f","--ifile"):
            filename=arg
            flow = True
        elif opt in ("d","--dump"):
            dump=True
        else:
             print("\n Improper command format")
             usage()
             sys.exit()
    if flow :
        #print(filename)
        if os.path.isfile(filename):
            #print("File name  : ",filename)
            openfile = open(filename,'rb')
            readfile = openfile.read()
            print("Entropy of file is ", H(readfile))
       
            pe=pefile.PE(filename)
            sizeofHeader = pe.OPTIONAL_HEADER.SizeOfHeaders
            unknownEntropy = []
            unknownPackedEntropy = []
            for section in pe.sections:
                init=section.VirtualAddress
                last=section.VirtualAddress+section.Misc_VirtualSize
                sectionData= readfile[init:last]
                unknownEntropy.append(HsetReduction(sectionData))

                hex_bytes = binascii.hexlify(sectionData)
                cleartext = hex_bytes.decode("utf-8")
                cipherText= encrypFile(cleartext)
                unknownPackedEntropy.append(HsetReduction(cipherText))
            TotalunknownEntropy= 0
            TotalunknownPackedEntropy = 0 
            for i in range (len(unknownEntropy)):
                TotalunknownEntropy = TotalunknownEntropy+ unknownEntropy[i]
                TotalunknownPackedEntropy = TotalunknownPackedEntropy+ unknownPackedEntropy[i]
            firstEntropy = TotalunknownEntropy/len(unknownEntropy)
            secondEntropy =TotalunknownPackedEntropy/len(unknownPackedEntropy)
            #print("First Entropy = ",firstEntropy)
            #print("Entropy after packing = ",secondEntropy)
            TestingList = [firstEntropy,secondEntropy,(secondEntropy-firstEntropy)]
            predictedResult = KNN.ibk(TestingList)
            print(filename," is ",predictedResult)
            #KNN.ibktest()
            if dump:
                print(dump_info(filename))
        
        else:
            print("File doesn't exit or path is improper")
    else:
        print("\n Improper command format")
        usage()
開發者ID:Kamlapati,項目名稱:skEntropy,代碼行數:77,代碼來源:skEntropy.py


注:本文中的KNN.ibk方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。