📄 131-134.html
字号:
<html><head><TITLE>Learn Encryption Techniques with BASIC and C++:Keyword-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=3//-->
<!--PAGES=131-134//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="128-131.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="134-136.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
</P>
<H4 ALIGN="CENTER"><A NAME="Heading13"></A><FONT COLOR="#000077">The DCIPHER5.CPP Program</FONT></H4>
<P>Once again a C++ version of a previously constructed BASIC language program is presented for readers who prefer this programming language. Maintaining our naming conventions, the C++ version of DCIPHER5.BAS is appropriately named DCIPHER5.CPP, while the executable version of the program is named DCIPHER5.EXE. To distinguish the executable version of DCIPHER5.BAS from DCIPHER5.CPP, remember that there are two directories on the CD-ROM accompanying this book and that source and executable BASIC programs are stored in the BASIC directory while C++ source and executable programs are stored in the C directory.
</P>
<P>Listing 3.8 contains the complete listing of DCIPHER5.CPP. As you read through the code you will note that, similar to the BASIC program, large segments of code were reused. Of particular interest is the function appropriately named decipher, which locates where the encrypted data is in the ciphertext.</P>
<P><B>Listing 3.8</B> The DCIPHER5.CPP program listing.</P>
<!-- CODE //-->
<PRE>
/*
dcipher5.cpp
C++ code written by Jonathan Held
using Microsoft Visual C++, version 5.0, on March 12, 1998.
*/
//standard include files
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
//function prototypes
bool checkInput(char * &);
void createAlphabet(char *, char[]);
void decipher(ifstream, ofstream, const char[], char[]);
void formatData(char []);
void getFileNames(char *&, char *&);
void getFileToDecipher(const char[], char[]);
bool getMessage(char* input, char* output, char msg_to_decipher[],
const char PTEXT[], const char CTEXT[]);
int getInputType();
void getKeyword(char *&);
void getShiftKey(char &);
void shiftKeyword(char [], char);
//constants we will use
const int FIVE = 5, TWENTYFIVE = 25, TWENTYSIX = 26,
TWENTYSEVEN = 27, SIXTYFIVE = 65, NINETY = 90,
NINETYTWO = 92, SIZE = 256;
//------------------------------------------------
//Function: main()
//Parameters: None
//Return Type: int - 0 execution is normal, 1 abnormal termination
//Purpose: Runs the main part of the program.
//------------------------------------------------
int main()
{
char plaintext[TWENTYSEVEN] = {'A','B','C','D','E','F','G','H',
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading14"></A><FONT COLOR="#000077">Alternative Relationships</FONT></H4>
<P>Up to this point the focus has been on using the development of a keyword-based mixed alphabet to create a ciphertext alphabet. Once that was accomplished, an alphabetic shift key was used to further mix the relationship between plaintext and ciphertext alphabets. In performing those tasks, the only information a message recipient requires is the keyword or keyword phrase and the alphabetic shift key to decipher a message through the use of a program. With a little knowledge of the method used to create a keyword-based mixed alphabet and the use of a shift key, most people can learn how to manually decipher a message. The major benefit of the previously described encipherment method is the ability of most persons to manually perform encipherment and decipherment with a minimum of information.
</P>
<P>You can extend the use of keyword or keyword phrase mixed alphabets and alphabetic shifting to the plaintext alphabet. In fact, you can develop nine common alphabetic relationships that are listed in Table 3.1. You could also reverse the resulting plaintext, ciphertext, or both plaintext and ciphertext alphabets to further increase the number of alphabetic relationships. However, this may add a degree of confusion to both encipherment and decipherment due to the large number of options users could be forced to consider and remember. To keep your techniques practical, I’ll simply illustrate the use of two keyword-based mixed sequence alphabets for enciphering a message and leave it to you to modify CIPHER5.BAS to obtain other plaintext-ciphertext relationships.</P>
<TABLE BORDER WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 3.1</B> Common alphabetic relationships
<TR>
<TD WIDTH="50%" VALIGN="TOP">plaintext alphabet in normal sequence
<TD WIDTH="50%">ciphertext alphabet in normal sequence and shifted
<TR>
<TD VALIGN="TOP">plaintext alphabet in normal sequence
<TD>ciphertext alphabet in keyword mixed sequence
<TR>
<TD VALIGN="TOP">plaintext alphabet in normal sequence
<TD>ciphertext alphabet in keyword mixed sequence and shifted
<TR>
<TD VALIGN="TOP">plaintext alphabet in keyword mixed sequence
<TD>ciphertext alphabet in normal sequence and shifted
<TR>
<TD>plaintext alphabet in keyword mixed sequence
<TD>ciphertext alphabet in keyword mixed sequence
<TR>
<TD VALIGN="TOP">plaintext alphabet in keyword mixed sequence
<TD>ciphertext alphabet in keyword mixed sequence and shifted
<TR>
<TD>plaintext alphabet in keyword mixed sequence and shifted
<TD>ciphertext alphabet in normal sequence and shifted
<TR>
<TD>plaintext alphabet in keyword mixed sequence and shifted
<TD VALIGN="TOP">ciphertext alphabet in keyword mixed sequence
<TR>
<TD>plaintext alphabet in keyword mixed sequence and shifted
<TD>ciphertext alphabet in keyword mixed sequence and shifted
</TABLE>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="128-131.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="134-136.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -