gpt4 book ai didi

C 程序可以在命令行中运行,但不能在 Python 脚本中运行?

转载 作者:行者123 更新时间:2023-11-30 09:56:50 26 4
gpt4 key购买 nike

更新了整个 python 脚本。

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

这是我的小 C 程序,名为 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 脚本...请注意,我不确定是否正确使用了 exit

    #!/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!!!

我对这部分进行了大量修改,但没有任何效果,这是怎么回事?它可以在命令行上运行,但不能在 python 中运行。例如, strip('\0')str(r"$") 是我最近进行的一些修改,但仍然不起作用。也许我会写一个 bash 脚本来代替......

请注意,编译后的 C 程序在命令行上执行其应执行的操作。

最佳答案

卫生部!我需要在我的 C 程序中返回 0。它现在正在运作只是为了让您知道。创建我的第一个哈希表:)

关于C 程序可以在命令行中运行,但不能在 Python 脚本中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23308221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com