我有以下字符串及其Base64编码的verison:
temp = "Last Star Wars 'not for children'\n\nThe sixth and final Star Wars movie may not be suitable for young children, film-maker George Lucas has said.\n\nHe told US TV show 60 Minutes that Revenge of the Sith would be the darkest and most violent of the series. \"I don't think I would take a five or six-year-old to this,\" he told the CBS programme, to be aired on Sunday. Lucas predicted the film would get a US rating advising parents some scenes may be unsuitable for under-13s. It opens in the UK and US on 19 May. He said he expected the film would be classified PG-13 - roughly equivalent to a British 12A rating.\n\nThe five previous Star Wars films have all carried less restrictive PG - parental guidance - ratings in the US. In the UK, they have all been passed U - suitable for all - with the exception of Attack of The Clones, which got a PG rating in 2002. Revenge of the Sith - the third prequel to the original 1977 Star Wars film - chronicles the transformation of the heroic Anakin Skywalker into the evil Darth Vader as he travels to a Hell-like planet composed of erupting volcanoes and molten lava. \"We're going to watch him make a pact with the devil,\" Lucas said. \"The film is much more dark, more emotional. It's much more of a tragedy.\"\n"
temp_enc = "TGFzdCBTdGFyIFdhcnMgJ25vdCBmb3IgY2hpbGRyZW4nXG5cblRoZSBzaXh0aCBhbmQgZmluYWwgU3RhciBXYXJzIG1vdmllIG1heSBub3QgYmUgc3VpdGFibGUgZm9yIHlvdW5nIGNoaWxkcmVuLCBmaWxtLW1ha2VyIEdlb3JnZSBMdWNhcyBoYXMgc2FpZC5cblxuSGUgdG9sZCBVUyBUViBzaG93IDYwIE1pbnV0ZXMgdGhhdCBSZXZlbmdlIG9mIHRoZSBTaXRoIHdvdWxkIGJlIHRoZSBkYXJrZXN0IGFuZCBtb3N0IHZpb2xlbnQgb2YgdGhlIHNlcmllcy4gXCJJIGRvbid0IHRoaW5rIEkgd291bGQgdGFrZSBhIGZpdmUgb3Igc2l4LXllYXItb2xkIHRvIHRoaXMsXCIgaGUgdG9sZCB0aGUgQ0JTIHByb2dyYW1tZSwgdG8gYmUgYWlyZWQgb24gU3VuZGF5LiBMdWNhcyBwcmVkaWN0ZWQgdGhlIGZpbG0gd291bGQgZ2V0IGEgVVMgcmF0aW5n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GRhcmssIG1vcmUgZW1vdGlvbmFsLiBJdCdzIG11Y2ggbW9yZSBvZiBhIHRyYWdlZHkuXCJcbg=="
>>> len(temp)
1251
>>> len(temp_enc)
1688
>>> len(temp)/3
417
>>> (len(temp)/3)*4
1668
字符串的长度可以被3整除。既然每3个字节我们就有4个字节的编码,那么为什么编码的字符串比预期的要长??为什么要在编码中添加填充?在
temp_enc
是temp
的base64编码:如果解码
^{pr2}$temp_enc
,则解码字符串的长度为1264,而不是1251:尽管
temp
包含换行符,\n
,temp_dec
包含后面跟n
s的文本反斜杠:如果您将
temp = base64.b64decode(temp_enc))
视为temp
,那么等于
这与每3个3字节的
temp
转换为4个temp_enc
字节的声明是一致的。在相关问题 更多 >
编程相关推荐