* [patch] encrypt.3: changed code for example usage
@ 2009-07-12 22:37 Rob Somers
[not found] ` <4A5A658D.1090200-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Rob Somers @ 2009-07-12 22:37 UTC (permalink / raw)
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA
This patch is against the 3.21 version of the man pages. I (and some
others) found that the original example code
did not seem to work as advertised. The new code (used by permission of
the original author, Jens Thoms Toerring) was found
on comp.os.linux.development.
Rob Somers
--- encrypt.3 2009-04-15 12:05:39.000000000 -0400
+++ encrypt.3.new 2009-07-12 18:31:23.000000000 -0400
@@ -129,27 +129,59 @@
.SH NOTES
In glibc 2.2 these functions use the DES algorithm.
.SH EXAMPLE
-You need to link with libcrypt to compile this example with glibc.
-To do useful work the
-.I key[]
-and
-.I txt[]
-arrays must be filled with a useful bit pattern.
+You need to link with libcrypt (-lcrypt) to compile this example with
glibc.
.sp
.nf
+/* Modified from original source code
+ * written by Jens Thoms Toerring. The original
+ * can be found on comp.os.linux.development.
+ */
+
#define _XOPEN_SOURCE
-#include <unistd.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
+#include <crypt.h>
-int
-main(void)
+int main(void)
{
- char key[64]; /* bit pattern for key */
- char txt[64]; /* bit pattern for messages */
+ char key[64];
+ char orig[9] = "eggplant";
+ char buf[64];
+ char txt[9];
+ int i, j;
+
+ for (i = 0; i < 64; i++) {
+ key[i] = rand() & 1;
+ }
+
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 8; j++) {
+ buf[i * 8 + j] = orig[i] >> j & 1;
+ }
+ setkey(key);
+ }
+ printf("Before encrypting: %s\n", orig);
+
+ encrypt(buf, 0);
+ for (i = 0; i < 8; i++) {
+ for (j = 0, txt[i] = '\0'; j < 8; j++) {
+ txt[i] |= buf[i * 8 + j] << j;
+ }
+ txt[8] = '\0';
+ }
+ printf("After encrypting: %s\n", txt);
+
+ encrypt(buf, 1);
+ for (i = 0; i < 8; i++) {
+ for (j = 0, txt[i] = '\0'; j < 8; j++) {
+ txt[i] |= buf[i * 8 + j] << j;
+ }
+ txt[8] = '\0';
+ }
+ printf("After decrypting: %s\n", txt);
- setkey(key);
- encrypt(txt, 0); /* encode */
- encrypt(txt, 1); /* decode */
+ return 0;
}
.fi
.SH "SEE ALSO"
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] encrypt.3: changed code for example usage
[not found] ` <4A5A658D.1090200-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-02-05 12:15 ` Michael Kerrisk (man-pages)
0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk (man-pages) @ 2015-02-05 12:15 UTC (permalink / raw)
To: Rob Somers
Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w,
linux-man-u79uwXL29TY76Z2rM5mHXA
On 07/13/2009 12:37 AM, Rob Somers wrote:
> I (and some
> others) found that the original example code
> did not seem to work as advertised. The new code (used by permission of
> the original author, Jens Thoms Toerring) was found
> on comp.os.linux.development.
Patch applied.
Thanks,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-05 12:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-12 22:37 [patch] encrypt.3: changed code for example usage Rob Somers
[not found] ` <4A5A658D.1090200-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-02-05 12:15 ` Michael Kerrisk (man-pages)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).