Snowcola/twisted_fate

Incorrect Padding

Closed this issue · 5 comments

I´m sorry, but I keep getting the same Incorrect Padding error when I try to decode a deck with the new cards. It works perfectly for decks with old cards. Could it be because we´re only loading the json from set 1? There´s another json for set 2 available, called:

set2-en_us.json

I tried to make it work on my own but failed.

Is this the error you are facing?
binascii.Error: Incorrect padding

I got them too when using these deck codes.

CIBQIAQGCQNCCMICAEBDOOIDAIBACAYJAMAQEBRQAMAQEAQMC4AQEAQGAIAQCARRAIBAMJRO
CIBAEAICAI4QUAQGAUFQ4FQ2EERSQMJ2AIAQCARBAEBAMHAA
CIBQIAQGDIQS2MIDAEBAENZZAQBAEAIDBEFAGAICAYJACAICAQAQEAQGAEAQEBRO
CIBAGAICBQLTSAYCAYNCCLQDAMAQEAQWG4AQEAQJAYBAMDQRCQTDCPIBAIAQEERR
CIBQIAQGCQNCCMICAEBDOOIDAIBACAYJAIBAEBROGABQCAQCBQLQGAICAYTACAICGEAQEAQG
CIBQEAQGCQQQEAICG44QIAQCAEBQMCIDAMBAMGRGGEBQCAQCAQYQCAQCBIBACAQGFYAQEAQF
CIBQEAQGBULASAICAYEQYEIVC4UDEOIBAIBAUAICAEBAEMIA

Did you manage to fix this yet?

I made this change - you can try to see if it works for you.

diff --git a/twisted_fate/deck_coder/deckCoder.py b/twisted_fate/deck_coder/deckCoder.py
index 55615b3..f32a9b2 100644
--- a/twisted_fate/deck_coder/deckCoder.py
+++ b/twisted_fate/deck_coder/deckCoder.py
@@ -28,9 +28,9 @@ class Base32:
             padding += result
             length += result
         """
-        padding = 8 - (length % 8)
-
-        b32String += "=" * padding
+        if (length%8 > 0):
+            padding = 8 - (length % 8)
+            b32String += "=" * padding
         return b32String

@chuanpeng I have incorporated your fix into twisted_fate. In future you can submit a pull request should you have any fixes. Package is now up to date on PyPI as well.