Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C程序可以从命令行工作,但不能从Python脚本工作?_C_String_Python 2.7_Hash_Machine Learning - Fatal编程技术网

C程序可以从命令行工作,但不能从Python脚本工作?

C程序可以从命令行工作,但不能从Python脚本工作?,c,string,python-2.7,hash,machine-learning,C,String,Python 2.7,Hash,Machine Learning,使用整个python脚本更新。 好的,我正在Coursera.org上学习一门机器学习课程,我想看看这些类型的算法可以用加密技术做些什么,并测试一下是否有可能用神经网络来破解加密。首先,我需要为一个训练集创建一个哈希表,但在C字符串数组、args和Python将字符串作为args传递给C程序时遇到了问题 这是我的lilc程序hashpipe #include <stdio.h> #define __USE_GNU #include <crypt.h>

使用整个python脚本更新。

好的,我正在Coursera.org上学习一门机器学习课程,我想看看这些类型的算法可以用加密技术做些什么,并测试一下是否有可能用神经网络来破解加密。首先,我需要为一个训练集创建一个哈希表,但在C字符串数组、args和Python将字符串作为args传递给C程序时遇到了问题

这是我的lilc程序hashpipe

    #include <stdio.h>
    #define __USE_GNU
    #include <crypt.h>
    #include <string.h>

    int main(int argc, char** argv){
            char * salt = argv[2];
            struct crypt_data data;
            data.initialized = 0;
            char * result = crypt_r(argv[1], id, &data);
            printf("%s\n", result);
            return 0 // This was the bugger!!! I forgot it!!!
    }
我一直在对这部分进行大量更改,但没有任何效果,这是怎么回事?它可以在命令行上工作,但不能在python中工作。例如,
strip('\0')
str(r“$”)
是我最近做的一些修改,但仍然不起作用。也许我会写一个bash脚本来代替

请注意,编译的C程序在cmd行上执行它应该执行的操作。

DOH!
我需要在我的C程序中返回0。现在工作只是为了让你知道。创建我的第一个排序哈希表:)

请提供示例输入,以使Python示例重现。
    #!/usr/bin/env python2.7

    import sys, random, subprocess

    pathToWL = str(sys.argv[1]) #Path to WordList
    pathForHT = str(sys.argv[2]) #Path to create Hash Table; no, its not smokable
    mId = str(sys.argv[3]) #id for use with crypt_r() see 'man 3 crypt_r'

    SaltCharSet = str("a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9")
    SaltCharSet = SaltCharSet.split(" ")

    try:
        fdWL = open(pathToWL, 'r')
    except:
        print "Could not open wordlist file."
        exit()

    try:
        fdHT = open(pathForHT, 'a')
    except:
        print "Could not open file for hash table"
        fdWL.close()
        exit()

    #We have our wordlist now step through the thing and start generating hashes.

    toStop = False
    cursor = 0 #Use the cursor later once this program evolves

    while(not toStop):
        try:
            ln = str(fdWL.readline())
        except:
            toStop = True
            continue
        ln = ln.strip("\n")
        if len(ln) < 6:
            continue
        # create random salts
        # send ln, id, and salts to hashpipe
        salt = []
        lenOfSalt = random.randint(6,16)
        while(len(salt) < lenOfSalt + 1):
            aORn = random.randint(0,1)
            if aORn == 0:# Its a letter
               uORl = random.randint(0,1)
                if uORl == 0:
                    salt.append(SaltCharSet[(random.randint(0,25))].upper())
                elif uORl == 1:
                    salt.append(SaltCharSet[(random.randint(0,25))].lower())
                else:
                    print "Random Int 'uORl' out of bounds"
                    fdHT.close()
                    fdWL.close()
                    toStop = True
                    exit() # I don't know what happened
                    break #in case exit() fails or is used incorrectly

            elif aORn == 1:# Its a number
                salt.append(SaltCharSet[(random.randint(26, 35))])
            else:
                print "Random Int 'aORn' out of bounds"
                fdHT.close()
                fdWL.close()
                toStop = True
                exit() # I don't know what happened
                break #in case exit() fails or is used incorrectly
        #Generated Salt
        salt = "".join(salt)
        wholeArg2 = str("$"+mId+"$"+salt)
        try:
            mHash = str(subprocess.check_output(["hashpipe", ln, wholeArg2]))
        except:
            print " error getting hash"
            #Clean-up
            fdHT.close()
            fdWL.close()
            toStop = True
            exit()
            break
        #Generated hash, now write it to the fdHT file
        print str(ln+" "+wholeArg2+"\t"+mHash)
        fdHT.write(str(ln+"\t"+mHash+"\n"))
        cursor = fdWL.tell()

    fdHT.close()
    fdWL.close()

    return 0 #Yes, I forgot it here too, probably why my script never ended! LOL!!! so simple!!!