Hi, everyone, i am a Python programmer and found use nimpy write python 
extention is super easy than Go,Rust, then i am try to write the code below:
    
    
    import nimpy
    import nimAES
    
    proc encrypt(n string): string  {.exportpy.} =
        var ctx: AESContext
        zeroMem(addr(ctx), sizeof(ctx))
        var key = "0123456789ABCDEF"
        if ctx:setEncodeKey(key):
            var out1 = newString(len(n))
            var output1 = cstring(out1)
            ctx.encryptECB(cstring(n), output1)
            return $output1
    
    
    
    Run

then compile the file pwgen.nim with
    
    
    nim c -d:release --app:lib --gc:regions --out:pwgen.so pwgen.nim
    
    
    Run

and using in python
    
    
    from pwgen import encrypt
    
    secret = "hello, world"
    
    print(encrypt(secret))
    
    
    Run

which output is byte and got decode error when turn it into string

Any advice are appreciate.

Reply via email to