Visual Studio 2019 C# 断点调试 & 凯撒密码,单码密码实现
【摘要】
1、断点调试
快捷键
F9:对选中的行设置断点F5:进入调试状态(不加断点时运行完程序不会直接退出)F11:逐语句调试,即进入下一个语句。F10:逐过程调试,即进入下一个过程(执行完整个函数)SHIT...
1、断点调试
快捷键
- F9:对选中的行设置断点
- F5:进入调试状态(不加断点时运行完程序不会直接退出)
- F11:逐语句调试,即进入下一个语句。
- F10:逐过程调试,即进入下一个过程(执行完整个函数)
- SHITF+F11为跳出调试,即执行当前执行点所在函数的剩下所有行。
- Ctrl+F5:进入运行状态(不调试)
调试过程:- 可以看到和修改实时值。
- 可以拖动选择下一条执行的语句。
- 可以实时编辑和修改代码
using System;
namespace Calculator
{
class Program
{
static void swap(ref int a, ref int b)//引用
{
int t = a; //断点F9
a = b; //逐语句F11
b = t;
Console.WriteLine("swap {0}", a);//SHITF+F11执行当前执行点所在函数的剩下所有行。
Console.WriteLine("swap {0}", t);
Console.WriteLine("swap {0}", b);
}
static void Main(string[] args)
{
int a = 5, b = 10;
Console.WriteLine("{0} {1}", a, b);//1. 查看和修改变量
Console.WriteLine("abcd"); //2.跳过语句
swap(ref a, ref b); //3.实时修改
// Console.WriteLine("{0} {1}", a, b);
swap(ref a, ref b); //逐过程F10 (执行完整个函数)
Console.WriteLine("{0} {1}", a, b);
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
2、凯撒密码、单码密码实现
凯撒密码:
using System;
namespace kaisa
{
class Program
{
public static string daxie(string str)
{ //大写化字母以及检查函数
string strs = "";
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
{
char x;
x = (char)(str[i] - 32);
strs = strs + x;
}
else if (str[i] >= 'A' && str[i] <= 'Z')
{
strs = strs + str[i];
}
else
{
return "!";
break;
}
}
return strs;
}
public static void jiami(string plaintexts, int keys)
{
//Console.WriteLine(keys);
string strs="";
for (int p = 0; p < plaintexts.Length; p++)
{ //输出密文
//Console.WriteLine((plaintexts[p] - 'A' + keys) % 26 + 'A'+'\n');
char ch = (char)((plaintexts[p] - 'A' + keys) % 26 + 'A');
strs = strs+ch;
}
Console.WriteLine("得到密文:");
Console.WriteLine(strs + "\n");
}
public static void jiemi(string plaintexts, int keys)
{
string strs = "";
for(int p = 0; p < plaintexts.Length; p++)
{
char ch = (char)((plaintexts[p] - 'A' - keys + 26) % 26 + 'A');
strs = strs + ch;
}
Console.WriteLine("得到明文:");
Console.WriteLine(strs + "\n");
}
static int Main(string[] args)
{
String choice;
Console.WriteLine("凯撒加密/解密");
while (true)
{
string plaintext;
string ciphertext;
int key;
Console.WriteLine("输入数字选择模式:");
Console.WriteLine("0.加密模式" + "\n");
Console.WriteLine("1.解密模式+\n");
Console.WriteLine("2.退出程序");
choice = Console.ReadLine();
switch (choice)
{
case "0": //加密
Console.WriteLine("\n请输入明文(连续字母串):");
plaintext = Console.ReadLine();
while (true)
{
if (daxie(plaintext) == "!")
{
Console.WriteLine("输入错误,请重新输入明文:");
plaintext = Console.ReadLine();
}
else
{
plaintext = daxie(plaintext);
break;
}
}
Console.WriteLine("\n请输入密钥(0-25数字):");
key = Convert.ToInt32(Console.ReadLine());
while (true)
{
if (key<0 || key>25)
{
Console.WriteLine("\n输入错误,请重新输入密钥:");
key = Convert.ToInt32(Console.ReadLine());
}
else
{
break;
}
}
jiami(plaintext, key);
break;
case "1": //解密
Console.WriteLine("\n请输入密文(连续字母串):");
ciphertext = Console.ReadLine();
while (true)
{
if (daxie(ciphertext) == "!")
{
Console.WriteLine("\n输入错误,请重新输入明文:");
ciphertext = Console.ReadLine();
}
else
{
ciphertext = daxie(ciphertext);
break;
}
}
Console.WriteLine("\n请输入密钥(0-25数字):");
key = Convert.ToInt32(Console.ReadLine());
while (true)
{
if (key < 0 || key > 25)
{
Console.WriteLine("\n输入错误,请重新输入密钥:");
key = Convert.ToInt32(Console.ReadLine());
}
else
{
break;
}
}
jiemi(ciphertext, key);
break;
case "2": //退出程序
Console.WriteLine("\n程序退出!!!");
return 0;
break;
default:
Console.WriteLine("输入错误,请重新选择!!!\n");
break;
}
}
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
单码密码(单表代换):
using System;
namespace 单码
{
class Program
{
public static string quchong(string str)
{ //密钥去重函数
string strs = "";
int[] vis = new int[26];
for (int i = 0; i < str.Length; i++)
{
if (vis[str[i] - 'A'] == 0)
{
strs = strs + str[i];
}
vis[str[i] - 'A']++;
}
return strs;
}
public static string daxie(string str)
{ //大写化字母以及检查函数
string strs = "";
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
{
char x;
x = (char)(str[i] - 32);
strs = strs + x;
}
else if (str[i] >= 'A' && str[i] <= 'Z')
{
strs = strs + str[i];
}
else
{
return "!";
break;
}
}
return strs;
}
public static void jiami(string plaintexts, string keys)
{ //加密函数
string miyao;
miyao = quchong(keys);
int[] vis = new int[26];
for (int i = 0; i < miyao.Length; i++)
{
vis[miyao[i] - 'A']++;
}
string canzhaos = miyao;
string tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < 26; i++)
{
if (vis[i] == 0)
{
canzhaos = canzhaos + tmp[i];
}
}
//Console.WriteLine(canzhaos);
string ans = "";
for (int p = 0; p < plaintexts.Length; p++)
{
ans = ans + canzhaos[(int)(plaintexts[p] - 'A')];
}
Console.WriteLine("得到密文:");
Console.WriteLine(ans + "\n");
}
public static void jiemi(string ciphertext, string keys)
{ //加密函数
string miyao;
miyao = quchong(keys);
int[] vis = new int[26];
for (int i = 0; i < miyao.Length; i++)
{
vis[miyao[i] - 'A']++;
}
string canzhaos = miyao;
string tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < 26; i++)
{
if (vis[i] == 0)
{
canzhaos = canzhaos + tmp[i];
}
}
char[] duizhao = new char[26];
for (int i = 0; i < canzhaos.Length; i++)
{
duizhao[canzhaos[i] - 'A'] = tmp[i];
}
string duizhaos = "";
for (int i = 0; i < 26; i++)
{
duizhaos = duizhaos + duizhao[i];
}
//Console.WriteLine(canzhaos);
string ans = "";
for (int p = 0; p < ciphertext.Length; p++)
{
ans = ans + duizhaos[(int)(ciphertext[p] - 'A')];
}
Console.WriteLine("得到明文:");
Console.WriteLine(ans + "\n");
}
static int Main(string[] args)
{
String choice;
Console.WriteLine("单码加密/解密");
while (true)
{
string plaintext;
string ciphertext;
string key;
Console.WriteLine("输入数字选择模式:");
Console.WriteLine("0.加密模式" + "\n");
Console.WriteLine("1.解密模式+\n");
Console.WriteLine("2.退出程序");
choice = Console.ReadLine();
switch (choice)
{
case "0": //加密
Console.WriteLine("\n请输入明文(连续字母串):");
plaintext = Console.ReadLine();
while (true)
{
if (daxie(plaintext) == "!")
{
Console.WriteLine("输入错误,请重新输入明文:");
plaintext = Console.ReadLine();
}
else
{
plaintext = daxie(plaintext);
break;
}
}
Console.WriteLine("\n请输入密钥(连续字母串):");
key = Console.ReadLine();
while (true)
{
if (daxie(key) == "!")
{
Console.WriteLine("\n输入错误,请重新输入密钥:");
key = Console.ReadLine();
}
else
{
key = daxie(key);
break;
}
}
jiami(plaintext, key);
break;
case "1": //解密
Console.WriteLine("\n请输入密文(连续字母串):");
ciphertext = Console.ReadLine();
while (true)
{
if (daxie(ciphertext) == "!")
{
Console.WriteLine("\n输入错误,请重新输入明文:");
ciphertext = Console.ReadLine();
}
else
{
ciphertext = daxie(ciphertext);
break;
}
}
Console.WriteLine("\n请输入密钥(连续字母串):");
key = Console.ReadLine();
while (true)
{
if (daxie(key) == "!")
{
Console.WriteLine("\n输入错误,请重新输入密钥:");
key = Console.ReadLine();
}
else
{
key = daxie(key);
break;
}
}
jiemi(ciphertext, key);
break;
case "2": //退出程序
Console.WriteLine("\n程序退出!!!");
return 0;
break;
default:
Console.WriteLine("输入错误,请重新选择!!!\n");
break;
}
}
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。
原文链接:gwj1314.blog.csdn.net/article/details/120690535
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)