我希望这很容易解决 . 我使用Python在Windows Powershell中获得的错误如下:

Traceback (most recent call last): File "[filename.py]", line 66, in main(ciphertext) NameError: name 'ciphertext' is not defined

我的代码:

def main():

# cipherOne contains encrypted Cesear cipher

myMessage = cipherOne

ciphertext = encryptMessage(key, myMessage)

# Print the encrypted string in ciphertext to the screen, with

# a | (called "pipe" character) after it in case there are spaces at

# the end of the encrypted message.

print(ciphertext)

def encryptMessage(key, message):

# Each string in ciphertext represents a column in the grid.

ciphertext = [''] * key

# Loop through each column in ciphertext.

for col in range(key):

pointer = col

# Keep looping until pointer goes past the length of the message.

while pointer < len(message):

# Place the character at pointer in message at the end of the

# current column in the ciphertext list.

ciphertext[col] += message[pointer]

# move pointer over

pointer += key

# Convert the ciphertext list into a single string value and return it.

return ''.join(ciphertext)

# call main() function.

if __name__ == '__main__':

main()

target = open (filenamenew, 'a')

target.write(ciphertext) #the error

target.close()

我可以将密文中的加密字符串打印到屏幕上,没有任何问题,但无法解决如何通过此错误,我可以将密文附加到.txt文件 .

python将文本文件加密后输出_Python:将Casear密码和柱状转置密码的加密输出写入.txt文件...相关推荐

  1. python 写txt 换行_python中写入txt文件需要换行,以及\r 和\n

    在Python中,用open()函数打开一个txt文件,写入一行数据之后需要一个换行 如果直接用 f.write('\n') 只会在后面打印一个字符串'\n',而不是换行' 需要用 f.write(' ...

  2. python 怎么表示sqlserver null_如何使用Python将sqlserver查询输出写入.txt文件?

    我是Python新手,尝试连接到sqlserverdb并将查询的输出转换成一个flat.txt文件.在 一些代码正在工作,但是只写了将近1000条记录,然后就停止了.在 Python版本:2.7.13 ...

  3. python列表数据写入txt文件_Python将列表数据写入文件(txt, csv,excel)

    写入txt文件 def text_save(filename, data):#filename为写入CSV文件的路径,data为要写入数据列表. file = open(filename,'a') f ...

  4. python读取txt文件写入-python 读取、写入txt文件的示例

    写入文件 使用open()函数和write()函数 但是有两种写法,分别是'a'和'w' 'a' 表示写入文件 若无该文件会直接创建一个 如果存在这个文件,会接着已有的内容的后面写入 with ope ...

  5. 单张、批量识别图片中文字(写入txt文件、窗口视图创建、打包.exe文件)(百度文字识别SDK+Python的GUI之tklinker+打包pyinstaller)

    昨天我姐问我有没有软件可以批量识别图片上的文字,她在帮客户做资料整理,但是用的方法只能一张一张上传识别,不仅效率低还浪费时间. ​我就找了找批量识别的软件,下载下来觉得:嗯?不错,界面也挺好,小东西做 ...

  6. python 文件写入多个参数_pandas 把数据写入txt文件每行固定写入一定数量的值方法...

    我遇到的情况是:把数据按一定的时间段提出.比如提出每天6:00-8:00的每个数据,可以这样做: # -*-coding: utf-8 -*- import pandas as pd import d ...

  7. python写入TXT文件乱码,且utf-8无效

    python写入TXT文件乱码,且utf-8无效 使用write函数写入txt文件,enconding='utf-8',得到的文件中部分中文乱码. 解决: 将代码改为: f1 = open(" ...

  8. python读取txt文件,写入txt文件

    一.读取txt文件 方法一: import numpy as npfile = open("../data/track_data.txt","r") list ...

  9. python将字符串写入txt文件_python将字符串以utf-8格式保存在txt文件中的方法

    python将字符串以utf-8格式保存在txt文件中的方法 如下所示: #ltp_data 字符串 写进777.txt 1. def save(filename, contents): fh = o ...

最新文章

  1. PTA 基础编程题目集 7-19 支票面额 C语言
  2. CentOS6.6配置iptables
  3. mysql设置定时任务
  4. 读取SD卡里面的BMP文件 显示到TFT上
  5. java计数循环及小技巧
  6. Linux中如何理解组的分类,Linux中用户和组管理
  7. win32 sdk C语言菜单,win32 sdk 设定/获取checkbox控件状态
  8. Python的那些隐藏特性
  9. MySQL · 源码分析 · MySQL 半同步复制数据一致性分析
  10. linux扫描硬盘故障命令
  11. iservice封装有哪些方法_Java基础之类与对象、封装、构造方法·6(重点)
  12. mod_signalwire.c:1009 Next SignalWire adoption
  13. 2020-05-08 工作中英语单词积累
  14. 机器学习 数据预处理之特征编码(归纳整理版)
  15. 如何理解图像深度:8bit、16bit、24bit、32bit; 16.7M色彩
  16. H3C交换机级联式堆叠配置方式
  17. 计算机网络中man是,计算机网络分类为LAN、MAN和()。
  18. MT【108】线面角最小
  19. BNNVGG2-VGG Net
  20. 微型计算机控制系统系统组成,微型计算机控制系统的组成

热门文章

  1. execel公式 java工具_PAP-快速开发框架:JAVA 计算器 自定义公式 解决EXCEL计算公式问题...
  2. python实现采样函数_python中resample函数实现重采样和降采样代码
  3. 计算机网络画出发送窗口变化,2010年7月计算机网络原理试题及答案
  4. php 后端 轻量 框架,GitHub - 22cloud/mixphp: 轻量 PHP 框架,基于 Swoole 的常驻内存型 PHP 高性能框架 (开发文档完善)...
  5. 图书管理系统可行性分析报告范例_会做可行性分析报告贺州专家团队*金
  6. imp-00017 oracle2298,急,imp怪異問題,請高手協助
  7. MATLAB(二)数据的输入
  8. HTTP状态码表格汇总
  9. 粒子群优化算法(Particle Swarm Optimization)的 Matlab(R2018b)代码实现
  10. 在 VC++ 中使用 内联汇编