Skip to content

Instantly share code, notes, and snippets.

@poochin
Created May 25, 2011 00:21
Show Gist options
  • Select an option

  • Save poochin/990047 to your computer and use it in GitHub Desktop.

Select an option

Save poochin/990047 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
ABCDEFGHIJKLMNOPQRSTUVWXYZ
QWERTYUIOPASDFGHJKLZXCVBNM?
に置換するプログラムを作る
A-Z 以外の文字は ? にする
サンプルの文字列は KSOIDHEPZ -> ALGORITHM
'''
import unittest
class TestSub(unittest.TestCase):
def setUp(self):
self.coded = 'KSOIDHEPZ'
pass
def testSub(self):
self.assertEqual(simpledecode(self.coded), 'ALGORITHM')
def simpledecode(str):
base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
subbed = 'QWERTYUIOPASDFGHJKLZXCVBNM'
subdict = {}
for i in xrange(0, len(base)):
subdict[base[i]] = subbed[i]
result = ''
for c in str:
if c in subdict:
result += subdict[c]
else:
result += '?'
return result
def main():
unittest.main()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment