📄 215-217.html
字号:
<html><head><TITLE>Learn Encryption Techniques with BASIC and C++:Transposition-based Monoalphabetic Substitution</TITLE>
<!-- BEGIN HEADER --><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><SCRIPT><!--function displayWindow(url, width, height) { var Win = window.open(url,"displayWindow",'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes');}//--></SCRIPT></HEAD><body bgcolor="ffffff" link="#006666" alink="#006666" vlink="#006666"><P>
<CENTER><B>Learn Encryption Techniques with BASIC and C++</B>
<FONT SIZE="-2">
<BR>
<I>(Publisher: Wordware Publishing, Inc.)</I>
<BR>
Author(s): Gil Held
<BR>
ISBN: 1556225989
<BR>
Publication Date: 10/01/98
</FONT></CENTER>
<P>
<!-- Empty Reference Subhead -->
<!--ISBN=1556225989//-->
<!--TITLE=Learn Encryption Techniques with BASIC and C++//-->
<!--AUTHOR=Gilbert Held//-->
<!--PUBLISHER=Wordware Publishing, Inc.//-->
<!--CHAPTER=4//-->
<!--PAGES=215-217//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="211-215.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="218-220.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="CENTER"><A NAME="Heading22"></A><FONT COLOR="#000077">The DCIPHER6.CPP Program</FONT></H4>
<P>Similar to the program DCIPHER6.BAS, its C++ version which is stored on the CD-ROM under the filename DCIPHER6.CPP has a large number of functions used in the same manner as its encipher version. Thus, in this section we will focus our attention on examining the function that provides the program with its decipherment capability. That function is the decipher function whose statements are given in Listing 4.9. Listing 4.9 includes a number of built-in comments that define the logic of the program. You can find the complete program and the executable version on the CD-ROM in the C directory.
</P>
<P><B>Listing 4.9</B> The C++ decipher function used in the program DCIPHER6.CPP.</P>
<!-- CODE //-->
<PRE>
//----------------------------------------------------------------
//Function: decipher()
//Parameters: in - the input file we are deciphering
// out - the output file we are writing the deciphered
// text to
// PTEXT - the plaintext alphabet (used to decipher)
// ctext - the ciphertext
//Return Type: None
//Purpose: Decipher the input file and write the contents to the
//output file specified by the user.
//----------------------------------------------------------------
void decipher(ifstream in, ofstream out, const char PTEXT[], char ctext[])
{
char enc_file_data[SIZE];
//continue this process until we get to the end of the file
while (in.getline(enc_file_data, SIZE, '\n')){
if (enc_file_data[0] == '/'){
out << enc_file_data << endl;
}
else {
//format the data - i.e., get rid of all spaces
formatData(enc_file_data);
//dump data to file
for (int ix=0; ix<strlen(enc_file_data); ix++){
//used to keep track of what plaintext character
//we are going to use
int jx;
for (jx=0; jx<TWENTYSIX; jx++){
//find where the encrypted data is in the
//ciphertext - this location corresponds to
//the plaintext character location
if (enc_file_data[ix] == ctext[jx])
break;
}
//conditionals for grouping by five and inserting
//new lines
if (!(ix%TWENTYFIVE))
out << endl;
if ((ix!=0) && (!(ix%FIVE))){
out << " " << PTEXT[jx];
}
else {
out << PTEXT[jx];
}
}
}
}
return;
}//end decipher()
</PRE>
<!-- END CODE //-->
<H3><A NAME="Heading23"></A><FONT COLOR="#000077">Monoalphabetic Combinations</FONT></H3>
<P>Regardless of the technique or techniques used to form a monoalphabetic cipher alphabet, the maximum number of trials necessary to correctly decipher a message remains the same. That number is 26!, which is approximately 4.0329E+26—a very large number. However, that large number can be very deceptive, as it is relatively easy for a trained cryptanalyst to decipher a lengthy message by a frequency analysis of the characters in the enciphered message. For example, E is the most common letter in the English language, followed by the letter T, which has the next highest frequency of occurrence. By performing a frequency analysis of the characters in an enciphered message a trained analyst may be able to note that E was replaced by one character, T by another, and so on. By deciphering a few characters correctly, patterns may become visually identifiable. For example, deciphering three enciphered characters as EET may provide the analyst with a clue that the character prefixing the first deciphered E is the plaintext M. This monoalphabetic substitution weakness means you should keep messages relatively short to hinder the possibility of a frequency analysis being used as a wedge by a cryptanalyst to initiate the deciphering of your message. This weakness also resulted in the development of polyalphabetic substitution encipherment and pseudo-random encipherment techniques—topics I will cover in the next two chapters of this book.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="211-215.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="218-220.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -