fork download
  1. # your code goes here
  2. """ base58 encoding / decoding functions """
  3. import unittest
  4.  
  5. alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
  6. base_count = len(alphabet)
  7.  
  8. def encode(num):
  9. """ Returns num in a base58-encoded string """
  10. encode = ''
  11.  
  12. if (num < 0):
  13. return ''
  14.  
  15. while (num >= base_count):
  16. mod = num % base_count
  17. encode = alphabet[mod] + encode
  18. num = num / base_count
  19.  
  20. if (num):
  21. encode = alphabet[num] + encode
  22.  
  23. return encode
  24.  
  25. def decode(s):
  26. """ Decodes the base58-encoded string s into an integer """
  27. decoded = 0
  28. multi = 1
  29. s = s[::-1]
  30. for char in s:
  31. decoded += multi * alphabet.index(char)
  32. multi = multi * base_count
  33.  
  34. return decoded
  35.  
  36. class Base58Tests(unittest.TestCase):
  37.  
  38. def test_alphabet_length(self):
  39. self.assertEqual(58, len(alphabet))
  40.  
  41. def test_encode_10002343_returns_Tgmc(self):
  42. result = encode(10002343)
  43. self.assertEqual('Tgmc', result)
  44.  
  45. def test_decode_Tgmc_returns_10002343(self):
  46. decoded = decode('Tgmc')
  47. self.assertEqual(10002343, decoded)
  48.  
  49. def test_encode_1000_returns_if(self):
  50. result = encode(1000)
  51. self.assertEqual('if', result)
  52.  
  53. def test_decode_if_returns_1000(self):
  54. decoded = decode('if')
  55. self.assertEqual(1000, decoded)
  56.  
  57. def test_encode_zero_returns_empty_string(self):
  58. self.assertEqual('', encode(0))
  59.  
  60. def test_encode_negative_number_returns_empty_string(self):
  61. self.assertEqual('', encode(-100))
  62.  
  63. if __name__ == '__main__':
  64. #print encode(int("00B94BA6C51B3D8372D82FDE5DC78773D960B5A82FCDAC8181",16))
  65. print hex(decode("Wh4bh"))
Success #stdin #stdout 0.02s 8092KB
stdin
SQLite format 3   @                                                                   . š
˜  # g                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ]
tablesettingssettingsCREATE TABLE settings (name TEXT,value TEXT, PRIMARY KEY (name))/C indexsqlite_autoindex_settings_1settings        3Aindexk_latency_timestampeventsCREATE INDEX k_latency_timestamp ON events (latency DESC, persistence DESC, timestamp ASC)ZƒtableeventseventsCREATE TABLE events (record_id TEXT,tenant_token TEXT NOT NULL,latency INTEGER,persistence INTEGER,timestamp INTEGER,retry_count INTEGER DEFAULT 0,reserved_until INTEGER DEFAULT 0,payload BLOB)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
   	= ï	=                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ‡/U!		Œl86BC0416-B17F-4FB9-9864-886DBA04977D4bb4d6f7cafc4e9292f972dca2dcde42-bd019ee8-e59c-4b0f-a02c-84e72157a3ef-7485”Q†?¯)3.0I	evt_statsq˜ê¼Ðé˜Ý©"o:4bb4d6f7cafc4e9292f972dca2dcde42Ë
i	Dell Inc.‰Latitude E6440 Ë
 Ë
I&c:6b3dbb93-2833-4456-aea7-7ddfd8907c14©Windows.Desktop Ë
‰Windows Desktop©,10.0.19041.1.amd64fre.vb_release.191206-1406 Ë
©
OneDriveSetupÉ
24.232.1118.3É
OneDriveSetup Ë
I	UnmeterediUnknown Ë 
)EVT-Windows-C++-No-3.4.276.7I$B1F7E2C3-67C8-456D-8AC6-EF9277530813q‰$0C5BBED2-6CD5-4874-A206-C268A961DC67 Ë!
i-06:00 Ë%
 É<	evt_statsËF
-	
bytesi33156 	evt_bytesi442682 
evt_bytes_maxi8139 
evt_bytes_mini588 evt_rcvi60 evt_snti6 freqi1800 kindistop ln_snti2 lr_snti4 off_typeiSQLite/Default pkg_acki7 pkg_drop_HTTP_403i1 pkg_drpi1 pkg_oki6 pkg_pndi7 rej_403i1 rtt_maxi639 rtt_mini73 	sess_timei
1736534525144 	snap_timei
1736534540207 	stat_timei
1736534525186   †U!		Š*8476071E-6397-4E04-BDEE-E6B0F3496C564bb4d6f7cafc4e9292f972dca2dcde42-bd019ee8-e59c-4b0f-a02c-84e72157a3ef-7485”Q†?¯)3.0I	evt_statsq˜ê¼Ðé˜Ý©"o:4bb4d6f7cafc4e9292f972dca2dcde42Ë
i	Dell Inc.‰Latitude E6440 Ë
 Ë
I&c:6b3dbb93-2833-4456-aea7-7ddfd8907c14©Windows.Desktop Ë
‰Windows Desktop©,10.0.19041.1.amd64fre.vb_release.191206-1406 Ë
©
OneDriveSetupÉ
24.232.1118.3É
OneDriveSetup Ë
I	UnmeterediUnknown Ë 
)EVT-Windows-C++-No-3.4.276.7I$B1F7E2C3-67C8-456D-8AC6-EF9277530813q‰$0C5BBED2-6CD5-4874-A206-C268A961DC67 Ë!
i-06:00 Ë%
 É<	evt_statsËF
-	

	evt_bytesi816 
evt_bytes_maxi816 
evt_bytes_mini816 evt_rcvi1 freqi1800 kindistop off_typeiSQLite/Default 	sess_timei
1736534525144 	snap_timei
1736534540207 	stat_timei
1736534540207   
   ç ôç                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           		”Q†?¯			”Q†?¯
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
stdout
0x1406e058