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

📄 291-294.html

📁 这个是密码学的经典著作
💻 HTML
字号:
<html><head><TITLE>Learn Encryption Techniques with BASIC and C++:Using Random Numbers</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=6//-->
<!--PAGES=291-294//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="286-291.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="294-300.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading12"></A><FONT COLOR="#000077">Modulo 26 Arithmetic</FONT></H4>
<P>To better understand the routine necessary to decipher the previously enciphered series of messages that used a random number-based enciphering program requires a review of modulo 26 addition and modulo 26 subtraction. Suppose the position values of the first four characters in a plaintext message with respect to their location in the sequential plaintext alphabet are 6, 2, 4, and 18, while a randomly generated number sequence based upon a defined seed was 12, 14, 22, and 17.
</P>
<P>The top of Figure 6.1 illustrates the enciphering process performed through the use of modulo 26 addition. Once the enciphered characters reach their destination, the same sequence of random numbers is used to reconstruct the original characters. However, this time modulo 26 subtraction is performed as illustrated in the bottom portion of Figure 6.1. When performing modulo 26 subtraction, if the numerator is smaller than the subtrahend you &#147;borrow&#148; 1, which in effect has a decimal value of 26, prior to performing the required subtraction. Thus, 9-17 becomes (26&#43;9)-17, or 18, when modulo 26 subtraction is performed.</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/06-01.jpg',493,291 )"><IMG SRC="images/06-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-01.jpg',493,291)"><FONT COLOR="#000077"><B>Figure 6.1</B></FONT></A>&nbsp;&nbsp;Enciphering and deciphering using modulo 26 addition and subtraction.</P>
<P>Now that you have an appreciation of the modulo subtraction process, let&#146;s focus our attention upon a small program developed to decipher a previously enciphered one-line message based upon a specified seed for the BASIC random number generator.
</P>
<H4 ALIGN="CENTER"><A NAME="Heading13"></A><FONT COLOR="#000077">The DRANDOM2.BAS Program</FONT></H4>
<P>Listing 6.7 contains the statements in the program DRANDOM2.BAS and three examples of its execution. In keeping with the file naming conventions previously established, I labeled the program DRANDOM2.BAS to indicate that it deciphers a message previously enciphered using the program RANDOM2.BAS.
</P>
<P><B>Listing 6.7</B> The DRANDOM2.BAS program listing and its repeated execution using different random seed numbers and different ciphertext messages to re-create a common plaintext message.</P>
<!-- CODE //-->
<PRE>
REM Program DRANDOM2.BAS
DIM KEY$(80), PLAINTEXT$(26)
CLS
   PRINT "Program DRANDOM2.BAS to demonstrate use of random numbers
                and"
   PRINT "random number seed in deciphering operations"
GOSUB INITIALIZE
START: PRINT
   INPUT "Enter a random seed number, 0 to terminate ", Y
   IF Y = 0 THEN STOP
   RANDOMIZE (Y)
   INPUT "Enter a one line message in UPPERCASE: ", TEXT$
   FOR I = 1 TO LEN(TEXT$)
   KEY$(I) = MID$(TEXT$, I, 1)
   NEXT I
REM Decipher
   PRINT "Deciphered message is               : ";
   FOR I = 1 TO LEN(TEXT$)
   FOR J = 0 TO 25
   IF PLAINTEXT$(J) = KEY$(I) GOTO GOTIT
   NEXT J
GOTIT: X = INT(RND * 100)
   IF X &gt; 25 THEN GOTO GOTIT
   IF J &lt; X THEN J = J &#43; 26
   Z = J - X
   PRINT PLAINTEXT$(Z);
   NEXT I
   GOTO START
INITIALIZE:
   RESTORE
   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

Program DRANDOM2.BAS to demonstrate use of random numbers and
random number seed in deciphering operations

Enter a random seed number, 0 to terminate 5
Enter a one line message in UPPERCASE: CPKWBXVSORN
Deciphered message is          : FIREFREDNOW
Enter a random seed number, 0 to terminate 8
Enter a one line message in UPPERCASE: RDMXNQVCJXE
Deciphered message is          : FIREFREDNOW
Enter a random seed number, 0 to terminate 51
Enter a one line message in UPPERCASE: ZXDDMCBNHGZ
Deciphered message is          : FIREFREDNOW
Enter a random seed number, 0 to terminate 0
</PRE>
<!-- END CODE //-->
<P>After entering the random number generator&#146;s seed number and the one-line enciphered message, the decipher routine matches each character in the message against the plaintext alphabet stored in the array PLAINTEXT$. Once a match occurs, you have located the correct position value or location of the ciphertext character in the plaintext character in the plaintext alphabet&#151;a value assigned to the variable J. After the value of J is obtained, a branch to the label GOTIT occurs and a random number between 0 and 25 is extracted. Because you must perform modulo 26 subtraction to reconstruct the plaintext character, compare the value of J to the value of <I>x</I> and increase J by 26 if the value of J is less than <I>x</I>. Then we subtract the value of <I>x</I> from the value of J, in effect performing modulo 26 subtraction. As indicated in the lower portion of Listing 6.7, this process enables you to reconstruct the plaintext message.</P>
<P>A comparison of the execution of RANDOM2.BAS and DRANDOM2.BAS contained in the lower portions of Listings 6.4 and 6.7 verifies the correctness of the deciphering process. That is, plaintext messages enciphered using a defined random number seed value in Listing 6.4 are entered as ciphertext messages in Listing 6.7 with the same seed number. This results in the correct decipherment of each message into its original plaintext contents.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="286-291.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="294-300.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>


</body></html>

⌨️ 快捷键说明

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