0

我正在尝试在 C++ 中执行此操作,我在 Python 中有一些代码,但我不知道如何使它在 C++ 中工作

def seguid(seq):

    try:
        #Python 2.5 sha1 is in hashlib
        import hashlib
        m = hashlib.sha1()
    except:
        #For older versions 
        import sha
        m = sha.new()
    import base64
    try:
        #Assume its a Seq object
        seq = seq.tostring()
    except AttributeError:
        #Assume its a string
        pass
    m.update(_as_bytes(seq.upper()))

    try:
        #For Python 2.5+
        return base64.b64encode(m.digest()).rstrip("=")
    except:
        #For older versions
        import os
        #Note: Using os.linesep doesn't work on Windows,
        #where os.linesep= "\r\n" but the encoded string
        #contains "\n" but not "\r\n"
        return base64.encodestring(m.digest()).replace("\n","").rstrip("=")
4

1 回答 1

0

我认为您可以将 python 代码嵌入到 C/C++ 代码中。有关详细信息,请参阅以下链接。

http://www.codeproject.com/Articles/11805/Embedding-Python-in-CC-Part-I

http://www.linuxjournal.com/article/8497

于 2013-02-07T06:19:47.860 回答