⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 047-050.html

📁 这个是密码学的经典著作
💻 HTML
字号:
<html><head><TITLE>Learn Encryption Techniques with BASIC and C++:Monoalphabetic Substitution Concepts</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=2//-->
<!--PAGES=047-050//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="042-047.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="050-056.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">Limiting the Effect of Errors</FONT></H4>
<P>The meaning of an enciphered message can be adversely affected by a human typing error or a transmission or transcription error. In such situations, a mistake which adds or omits a character would jumble the decipherment of the meaning of a message. Thus, we need a mechanism to limit the effect of errors caused by humans or technology. One common mechanism has its roots dating to the development of military systems and is known as character grouping&#151;the most common method being the placement of enciphered text into groups of five characters for transmission.
</P>
<P>To place ciphertext into groups of five characters, we will modify the CIPHER2.BAS and CIPHER2.CPP programs by the inclusion of a new subroutine. That subroutine, appropriately named GROUPBY5, replaces the subroutine PRTOUT contained in the CIPHER2.BAS program.</P>
<H4 ALIGN="CENTER"><A NAME="Heading14"></A><FONT COLOR="#000077">The GROUPBY5 Subroutine</FONT></H4>
<P>Listing 2.7 lists the contents of the subroutine GROUPBY5. That subroutine uses the variable L as a group counter. When invoked, the subroutine sets the value of L to 1. The FOR-NEXT loop in the subroutine prints one character at a time through the use of the MID$ function, which extracts a character from the string variable TEXT$. After a character is printed, the value of the FOR-NEXT loop index (I) divided by 5 is compared to the value of L. If the value of I/5 equals the value of L, five characters have been printed and a branch to the label 6 occurs. At that label, the PRINT statement generates a space. If the value of I/5 does not equal the value of L, a branch to the label 7 occurs and the FOR-NEXT loop terminates the current index value of the loop.
</P>
<P><B>Listing 2.7</B> The GROUPBY5 subroutine.</P>
<!-- CODE //-->
<PRE>
GROUPBY5:
  L = 1
  FOR I = 1 TO MSGLEN
  PRINT MID$(TEXT$, I, 1)
  IF I / 5 = L THEN GOTO 6
  GOTO 7
6 PRINT ' ';
  L = L &#43; 1
7 NEXT I
RETURN
</PRE>
<!-- END CODE //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR>One of the more famous messages transmitted using groupings of five characters was sent by Takeo Yoshikawa, a Japanese naval ensign assigned as a consulate secretary to the Japanese consulate in Honolulu. At 6 <TT>P.M.</TT> on December 6, 1941, he sent his final message using what was known as Oite to the Japanese and PA-K2 to American codebreakers. This message contained 44 groups of five characters and was transmitted to Tokyo via RCA communications at a cost of $6.82.
<P>The message transmitted by ensign Yoshikawa reported the arrival of an American battleship and mine sweeper into port and provided a summary of the number of ships at anchor and ships in dock in Honolulu by category&#151;battleships, light cruisers, destroyers, and mine sweepers. The message also noted that it appeared that no air reconnaissance was being conducted by the U.S. fleet&#146;s air arm.
</P>
<P>Although American cryptanalysts were able to crack messages transmitted in a PA-K2 code, doing so required an average of three days. Unfortunately, the contents of this message were deciphered well after the attack on Pearl Harbor had begun.<HR></FONT>
</BLOCKQUOTE>
</P>
<H4 ALIGN="CENTER"><A NAME="Heading15"></A><FONT COLOR="#000077">The CIPHER3.BAS Program</FONT></H4>
<P>Listing 2.8 contains the listing of the main body of the program CIPHER3.BAS. That program includes the subroutine GROUPBY5 which groups a line of enciphered text into groups of five characters. Figure 2.5 illustrates an example of the execution of the CIPHER3.BAS program using the alphabetic shift key B, and shows the five-character grouping of the enciphered message. If you are familiar with military systems, you may wonder why the GROUPBY5 subroutine leaves the last group with less than five characters instead of filling the group by adding X&#146;s or some similar group terminator character. The reason for not doing so at this time is because this program only operates on one message line at a time. Thus, before you terminate an unfilled group, you should first modify our program to read and process multiple lines of plaintext.
</P>
<P><B>Listing 2.8</B> The CIPHER3.BAS program listing.</P>
<!-- CODE //-->
<PRE>
REM PROGRAM CIPHER3.BAS
DIM PLAINTEXT$(25), CIPHERTEXT$(25)
CLS
       GOSUB INITIALIZE
1       INPUT "Enter UPPERCASE Alphabetic Shift Key: ", K$
       FOR I = 0 TO 25
       IF K$ = PLAINTEXT$(I) GOTO 2
       NEXT I
       PRINT "You must enter a letter from A to Z"
       GOTO 1
2       REM Position I represents shift key letter
GOSUB FORMCIPHER
       PRINT "Enter your message in UPPERCASE:"
       INPUT TEXT$
       MSGLEN = LEN(TEXT$)
GOSUB MSGENCIPHER
       REM Print results
       PRINT "Resulting enciphered message is:"
GOSUB GROUPBY5
STOP
INITIALIZE:
       REM Initialize plaintext values
       FOR I = 0 TO 25
       READ PLAINTEXT$(I)
       NEXT I
       DATA "A","B","C","D","E","F","G","H","I","J","K","L","M","N"
       DATA "O","P","Q","R","S","T","U","V","W","X","Y","Z"
RETURN
FORMCIPHER:
       REM Routine to form CIPHERTEXT alphabet based upon defined shift key
       J = I &#43; 1
       FOR K = 0 TO 25
       CIPHERTEXT$(K) = PLAINTEXT$((K &#43; J) MOD 26)
       NEXT K
RETURN
MSGENCIPHER:
       REM Convert plaintext to ciphertext
       FOR I = 1 TO MSGLEN
       FOR J = 0 TO 25
       IF MID$(TEXT$, I, 1) = PLAINTEXT$(J) THEN GOTO 5
       NEXT J
5       MID$(TEXT$, I, 1) = CIPHERTEXT$(J)
       NEXT I
RETURN
GROUPBY5:
       L = 1
       FOR I = 1 TO MSGLEN
       PRINT MID$(TEXT$, I, 1);
       IF I / 5 = L THEN GOTO 6
       GOTO 7
6       PRINT " ";
       L = L &#43; 1
7       NEXT I
RETURN
END
</PRE>
<!-- END CODE //-->
<P><A NAME="Fig5"></A><A HREF="javascript:displayWindow('images/02-05.jpg',448,124 )"><IMG SRC="images/02-05t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/02-05.jpg',448,124)"><FONT COLOR="#000077"><B>Figure 2.5</B></FONT></A>&nbsp;&nbsp;A sample execution of the program CIPHER3.BAS.<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="042-047.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="050-056.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>


</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -