Reading Programming

Jan 21, 2003 17:28 # 8076

Jaz *** has all the information you need...

Simple public key cryptography

81% | 2

Here is a minimalist Perl script that checks a RSA key for validity, then enciphers a simple message and deciphers it again. I post it here in case someone could be interested in the basic concept behind public key cryptography.

#!/usr/bin/perl

# Simple public-key cryptography script
# ----------------------------------------------------------------
# 2002 by Henning Koch
#
# Checks an RSA key for validity, then enciphers a simple message
# and deciphers it again.

# Public key is ($n, $b)
# Private key is ($p, $q, $a)
# Message is $x

use strict;

my ($n, $a, $b, $p, $q, $x) = (195487, 178791, 759, 839, 233, 101010);

sub square_and_multiply # computes g^l mod n
	{
	my ($g, $l, $n) = @_; 	
	
	my($x, $y, $m) = (1, $g, $l);
	
	while($m > 0)
		{
		if($m % 2 == 1)
			{
			$x = ($x*$y) % $n;
			$m--;
			}
			else
			{
			$y = ($y*$y) % $n;
			$m = $m / 2;
			}
		}
	
	return $x;
	}

sub is_prime
	{
	my ($i) = @_;
	use integer;
	foreach my $test (2 .. $i / 2) 
		{
		if($i % $test == 0) { return 0 }
		}
	return 1;
	}

my $enciphered = &square_and_multiply($x, $b, $n);
my $deciphered = &square_and_multiply($enciphered, $a, $n);

print "n = pq: " . ($n == $p * $q) . "\n";
print "ab = 1 mod eul(n): " . ( ($a*$b) % (($p - 1)*($q - 1)) == 1) . "\n";
print "p is prime: " . &is_prime($p) . "\n";
print "q is prime: " . &is_prime($q) . "\n";
print "p <> q: " . ($p != $q) . "\n";
print "Enciphered x: " . $enciphered . "\n";
print "Re-deciphered x: " . $deciphered . "\n";

'Yeah, That's what Jesus would do. Jesus would bomb Afghanistan. Yeah.' - snowlion

This post was edited by Jaz on Jan 21, 2003.

Jan 21, 2003 23:29 # 8096

frank *** is getting sarcastic...

Re: Simple public key cryptography

17% | 7

This post was deleted by request of the author.

This post was edited by frank on Jan 22, 2003.

Jan 22, 2003 06:45 # 8104

schatten *** replies...

Re: Simple public key cryptography

Oh my, hurry pinch me. Am I dreaming??? Am I actually seeing code that Jaz wrote??? This can't be. Its gotta be a bug in the system. Surely I am not seeing Jaz's code... This is totally amazing. Now if Jaz can release code I'm sure Microsoft will do it eventually.

Jaz what are the licensing terms to this script? Surely we can't modify it and let others use our modified code.

that's almost exactly what i thought when i saw this. but i don't think it's a good idea to get sarcastic on jaz's first steps in the world of open .. err .. published source ;>

great work, jaz! keep it up :)

Note that, u. o. u., s. is not a computer program and his answers might not always be appropriate.

Jan 22, 2003 08:24 # 8105

Jaz *** replies...

Hollow

This post is far to contraversal

Controversial is an opinion that differs from the majority. What you do is just being hollow. The fact that you spent the major part of your post declaring how hollow you are doesn't make you look less like an ass in any respect.

'Yeah, That's what Jesus would do. Jesus would bomb Afghanistan. Yeah.' - snowlion

Jan 22, 2003 10:00 # 8106

null isn't happy...

Re: Simple public key cryptography

91% | 2

This post is far to contraversal.

If you call senseless flames "controversial", yes.

Say, and that's something I'd really like to know, why the fsck are you always provoking people and practically begging for reds? Can't you just be nice? Is it because you have that urge to demonstrate social incompetence? What the heck do you get from pissing people off this way? If you just don't like this place anymore, you could just stay away from it and never bother with it again. There's absolutely no need to provoke people until you get kicked out.
Is this so hard to grasp?

When life hands you a lemon, that's 40% of your RDA of vitamin C taken care of.

Jan 23, 2003 01:40 # 8127

frank *** replies...

Re: Simple public key cryptography

74% | 2

This post was deleted by request of the author.

Jan 23, 2003 08:45 # 8137

null replies...

Re: Simple public key cryptography

?% | 1

This harkens back to the days when the big flame wars about open source were going on. Many of you will not remember because you weren't around NAO those days.

I've been there, and I remember. I also remember you doing things that... well, things people could understand as sabotage. Just because you didn't like NAO's closed-source character. (Whatever happened to your open-source rival site anyway?)

Thats why I get alot of red ratings. Because I have differing views than the majority of NAO readers.

Sorry to kill your soap bubble here, buddy. If you get a red from me, it's because I feel you're actively trying to offend me. Different opinions are perfectly acceptable for me. The way you declare yours is not.
As many people seem to have similar thoughts, you might want to reconsider your style. When people don't like what you write, it's not always because they can't take the genius of your oh-so controversial yet brilliant statements (altho that must be a tempting thought) - more often it's plain and simply because your inappropriate way of telling it pisses them off.

When life hands you a lemon, that's 40% of your RDA of vitamin C taken care of.

Jan 23, 2003 15:10 # 8151

frank *** replies...

Re: Simple public key cryptography

This post was deleted by request of the author.

Jan 23, 2003 15:18 # 8153

null has all the information you need...

Re: Simple public key cryptography

Like? I'd like to hear some examples of this sabotage.

Remember your resolution to bring NAO down because it's evil closed-source?

Nothing ever happened to it. Because there was never any open source rival site made.

Well my humble self remembers a story on NAO with a screenshot (? not sure about that one), and even some half-working title page. I can't remember the name tho.

When life hands you a lemon, that's 40% of your RDA of vitamin C taken care of.

Jan 23, 2003 15:22 # 8154

frank *** replies...

Re: Simple public key cryptography

This post was deleted by request of the author.

This post was edited by frank on Jan 23, 2003.


Favorites (edit)

Small text Large text

Netalive Amp (Skin for Winamp)