找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3504|回复: 1

[求助] 代码运行无结果, 显示RESTART。 哪位知道如何处理,帮看下

1

主题

1

帖子

1

积分

贫民

积分
1
BetweenWords 发表于 2017-10-1 13:43:39 | 显示全部楼层 |阅读模式
一段对换位加密算法解密的程序,具体代码附在后面。
正常在shell 中执行的正确结果

分开在shell中的执行结果

分开在shell中的执行结果
程序代码

程序代码

 程序代码

程序执行后显示:RESTART

程序执行后显示: RESTART

程序执行后显示: RESTART



代码如下:
import math

def main():
    myMessage = 'Cenoonommstmme oo smnio. s s c'
    myKey = 8

    plaintext = decryptMessage( myKey, myMessage )
    # Print with a | ( called "pipe" character ) after it in case
    # there are spaces at the end of the decrypted message.
    print( plaintext + '|' )

def decryptMessage( key, message ):

    # The transposition decrypt function will simulate the "columns" and "rows" of the grid that the plaintext is written on by using a list of strings. First, we need to calculate a few values.

    # The number of "columns" in our transposition grid:
    numOfColumns = math.ceil( len(message) / key )
    # The number of "rows"
    numOfRows = key
    # The number of "ShadeBoxes"
    numOfShadeBoxes = ( numOfColumns * numOfRows ) - len(message)
    # Each string in plaintext represents a column in the grid.
    plaintext = [''] * numOfColumns

    # The col and row varibles point to where in the grid the next character in the encrypted message will go.
    col = 0
    row = 0

    for symbol in message:
        plaintext[col] += symbol
        col += 1 # point to nest column

        # If there are no more columns or we're at a shaded box, go back to the first column and the next row.

        if( (col == numOfColumns) or ( ( col == numOfColumns - 1 ) and ( row >= numOfRows - numOfShadeBoxes ) ) ):
            col = 0
            row += 1
    return ''.join( plaintext )

# If transpositionDecrypt.py is run( instead of imported as a module ) call the main() function.
if __name__ == '__main__ ':
    main()


回复

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2017-10-4 12:05:09 | 显示全部楼层
从命令行执行
python3.4.4, win10
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表