Skip to content

Instantly share code, notes, and snippets.

@PyYoshi
Created June 4, 2012 10:28
Show Gist options
  • Select an option

  • Save PyYoshi/2867657 to your computer and use it in GitHub Desktop.

Select an option

Save PyYoshi/2867657 to your computer and use it in GitHub Desktop.
指定block sizeまでパッディングするlambda関数。 lambdaってちょー便利!
# coding:utf8
#!/usr/bin/env python
mes = "python prpr"
block_size = 32
padding = 'x'
pad = lambda s: s + (block_size - len(s) % block_size) * padding
print pad(mes)
@PyYoshi
Copy link
Copy Markdown
Author

PyYoshi commented Jun 5, 2012

ついでに16の倍数で埋める奴。気づく人は気づくであろうAESのpaddingに2つとも使ってます :)
pad16 = lambda s: s+(16-len(s))_padding if len(s)<16 else s+(16-(len(s)%16))_padding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment