Skip to content

Instantly share code, notes, and snippets.

@Nircek
Last active March 11, 2018 18:52
Show Gist options
  • Select an option

  • Save Nircek/9b4df55d89fa040c2eabb81b2060db2f to your computer and use it in GitHub Desktop.

Select an option

Save Nircek/9b4df55d89fa040c2eabb81b2060db2f to your computer and use it in GitHub Desktop.
Szyfrująca
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# code from Nircek's gist "Szyfrująca" https://gist.github.com/Nircek/9b4df55d89fa040c2eabb81b2060db2f
# licensed under MIT license
# MIT License
# Copyright (c) 2018 Nircek
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Program do szyfrowania tą samą metodą, co w grze Cypher o nazwie TRASPOSITION PUZZLE 08 [ADVANCED]
import math
def x(s=None):
# 0. get text from user
# this program was written by Nircek
if s == None:
s = input()
s = str(s)
# 1. UPPER CASE
# THIS PROGRAM WAS WRITTEN BY NIRCEK
s = s.upper()
# 2. delete spaces
# THISPROGRAMWASWRITTENBYNIRCEK
s = s.replace(' ', '')
# 3. length
# 29
l = len(s)
# 4. ceil(sqrt(29))
# 6
x = math.ceil(math.sqrt(l))
# 5. ceil(29/6)
# 5
while True:
y = math.ceil(l/x)
# 6. if (6*5 mod 4 != 2) increment 6 and goto 5
# false
if x*y % 4 == 2:
break
x += 1
# 7. expand string with 'Z' chars to create 6*5 length string
# THISPROGRAMWASWRITTENBYNIRCEKZ
s += 'Z' * (x*y-l)
l = len(s)
# 8. create new list with 5 stings
# ['','','','','']
r = [''] * y
# 9. append next letters to i%5 list
# ['TRMRNR','HOWIBC','IGATYE','SRSTNK','PAWEIZ']
for i in range(l):
r[i%y] += s[i]
# 10. join its elements
# TRMRNRHOWIBCIGATYESRSTNKPAWEIZ
r = ''.join(r)
# 11. add space behind every 4 chars
# TRMR NRHO WIBC IGAT YESR STNK PAWE IZ
rs = ''
for i in range(l//4):
rs += r[i*4:(i+1)*4] + ' '
rs += r[-2:]
return rs
print(x())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment