Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KEY ERROR ? #5

Open
pilattebe opened this issue Dec 1, 2017 · 3 comments
Open

KEY ERROR ? #5

pilattebe opened this issue Dec 1, 2017 · 3 comments

Comments

@pilattebe
Copy link

What am I doing wrong ?
Does this module support numbers (str) ?

Traceback (most recent call last):
  File "TP10hoff.py", line 54, in <module>
    open('test.by','w').write(base65536.encode(ret))
  File "/Users/benoit/anaconda3/lib/python3.6/site-packages/base65536/core.py", line 117, in encode
    code_point = BLOCK_START[b2] + b1
KeyError: '1'
@Artifact0
Copy link

is the KeyError output the second unencoded character of your input?
I tried with "hello world" and got KeyError 'e'
Also tried with "Software version ...." and got KeyError 'o'
That was the case with nothing before the string inside the encode() command,
and also with a 'u' before the string. I am having these failures at the encode stage.
When I tried with encode(b"Hello World") as it shows in readme usage, got this output

  File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-5: cha
racter maps to <undefined>

Anybody else experiencing this? Could this be part of my configuration? Is there a missing dependency I am overlooking? Could a later version of python fix it? Any tips at all?
Thanks for making this, am hoping to use it in projects.

@Parkayun
Copy link
Owner

I will look for it when I free. Not a soon. (I look forward to contribution. It would be very pleasure)
Thanks.

@Artifact0
Copy link

I got it to work by updating the system I am using it on. Was trying on Windows 5.x with Python 3.4.x and could not upgrade to Python 3.7 because Windows 5... On Windows "7" (6.x) with Python 3.7 I am able to encode and decode bytes. Now am looking for how to save encoded text in files.
I think the KeyErrors issue may be from not encoding text as bytes, and the other issue I had was due to python 3.4 compatibility
It seems that if you wish to use strings in a variable such as

x = "x"
xyz = x+"yz"

then the use for base65536.encrypt() should be

zyx_e = base65536.encrypt(xyz.encode())
zyx_d = base65536.decrypt(zyx_e).decode()

This is to switch encoding between string and bytes.
I made two simple functions which clean that up during use

def b65ke(input):
    bytes = input.encode()
    b65k= base65536.encode(bytes)
    return b65k
def b65kd(input):
    bytes = base65536.decode(input)
    string = bytes.decode()
    return string

have not got it to work with int as int because int has no len(). also have not tried with files yet. but int works the same as other strings if you just use str(x) on the int, and a handler could be built in. I may work an int/str handler later into the simple function above.
Thanks for replying so quick btw @Parkayun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants