[genius] Sat Sep 06 10:24:33 2014 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [genius] Sat Sep 06 10:24:33 2014 Jiri (George) Lebl <jirka 5z com>
- Date: Sat, 6 Sep 2014 15:25:21 +0000 (UTC)
commit b7e7a56b0cb4a9e6e10d96e7df5f8abe09ec61dd
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date: Sat Sep 6 10:25:05 2014 -0500
Sat Sep 06 10:24:33 2014 Jiri (George) Lebl <jirka 5z com>
* src/gnome-genius.gel: fix New Program crash
* examples/easy-matrix-examples.gel, examples/rsa.gel: Add
code for creating nice classroom examples for easily hand
computable RREF and eigenvalues, and add an example of computing
an RSA key and encryption/decryption with it
ChangeLog | 9 +++++
examples/Makefile.am | 4 ++-
examples/easy-matrix-examples.gel | 59 +++++++++++++++++++++++++++++++++++++
examples/rsa.gel | 49 ++++++++++++++++++++++++++++++
src/gnome-genius.c | 2 +-
5 files changed, 121 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 04ee6a1..fceb630 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Sep 06 10:24:33 2014 Jiri (George) Lebl <jirka 5z com>
+
+ * src/gnome-genius.gel: fix New Program crash
+
+ * examples/easy-matrix-examples.gel, examples/rsa.gel: Add
+ code for creating nice classroom examples for easily hand
+ computable RREF and eigenvalues, and add an example of computing
+ an RSA key and encryption/decryption with it
+
Fri Sep 05 21:20:02 2014 Jiri (George) Lebl <jirka 5z com>
* src/graphing.c: Add PlotWindowPresent
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 0f112ea..2cc5878 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -17,7 +17,9 @@ example_DATA = \
taylor-exp.gel \
taylor-sin.gel \
fourier-series-animation.gel \
- fourier-series-half-sawtooth.gel
+ fourier-series-half-sawtooth.gel \
+ rsa.gel \
+ easy-matrix-examples.gel
EXTRA_DIST = \
$(example_DATA)
diff --git a/examples/easy-matrix-examples.gel b/examples/easy-matrix-examples.gel
new file mode 100644
index 0000000..738572f
--- /dev/null
+++ b/examples/easy-matrix-examples.gel
@@ -0,0 +1,59 @@
+# Category: Linear Algebra
+# Name: Finding simple integer matrices (good classroom examples)
+
+#
+# Eigenvalues
+# -----------
+#
+# Find an integer matrix with given eigenvalues.
+#
+
+# Start with the eigenvalues
+D = diag(1,2,3);
+do (
+ # Find some eigenvectors
+ do (
+ E = randint(11,3,3) - 5*ones(3,3)
+ ) while det(E) == 0;
+ # Make the matrix
+ A = E*D*E^-1;
+) while not IsMatrixInteger(A);
+print("Integer matrix with given egeinvalues");
+# print A
+A
+
+#
+# Row reduction
+# -------------
+#
+# Integer matrix where the row reduced form is also
+# integer. That is find a random 3 by 4 matrice with
+# reduced row echelon form (rref) with only integer entries.
+# The entries of the matrix are between -5 and 5.
+
+do (
+ B = randint (11,3,4) - 5*ones(3,4)
+) while not IsMatrixInteger(rref(B));
+print("Integer matrix with integer RREF form");
+# print B
+B
+# print rref(B)
+rref(B)
+
+#
+# Row reduction with free variables
+# ------------------------------------------
+#
+# Find a random 3 by 4 matrix with reduced row echelon
+# form (rref) with only integer entries, the entries of the matrix are between
+# -5 and 5. Furthermore the rref form will have a zero row, so probably will
+# be a consistent system with some free variables.
+
+do (
+ C = randint (11,3,4) - 5*ones(3,4)
+) while not IsMatrixInteger(rref(C)) or CountZeroColumns(rref(C).') == 0;
+print("Integer matrix with integer RREF form that includes zero row");
+# print C
+C
+# print rref(C)
+rref(C)
diff --git a/examples/rsa.gel b/examples/rsa.gel
new file mode 100644
index 0000000..e58682c
--- /dev/null
+++ b/examples/rsa.gel
@@ -0,0 +1,49 @@
+# Category: Number Theory
+# Name: RSA example
+
+#
+# This code is maybe more for reading through than for simply running,
+# you should read perhaps the Wikipedia page on RSA if you are not
+# familiar: http://en.wikipedia.org/wiki/RSA_(cryptosystem)
+#
+
+# We want to print the whole numbers, be careful about about other code
+# run after this, you should maybe set these back after you are done playing
+# around with number theory (by default they are false and 12 respectively)
+FullExpressions = true;
+MaxDigits = 0;
+
+# Find a random modulus of the form n=p*q, we are not testing how good
+# (strong) the key will b
+p = NextPrime (randint (2^256)+2^255);
+q = NextPrime (randint (2^256)+2^255);
+n = p*q;
+phi = (p-1)*(q-1);
+print("The modulus (n=p*q is the modulus):");
+DisplayVariables(`p,`q,`n,`phi);
+
+# 'e' is taken, so using ex for the encryption exponent
+do (
+ ex = randint(2^64)+3;
+) while gcd(ex,phi) != 1;
+
+# compute the decryption exponent
+d = ex^-1 mod phi;
+
+print("The exponents:");
+DisplayVariables(`ex,`d);
+
+print("(n,ex) will be the public key for encryption");
+print("(n,d) will be the private key for decryption");
+
+print ("The message:");
+m = randint(100000000);
+DisplayVariables(`m);
+
+c = m^ex mod n;
+print ("The encnrypted message:");
+DisplayVariables(`c);
+
+dm = c^d mod n;
+print ("The decrypted message (should be same as m):");
+DisplayVariables(`dm);
diff --git a/src/gnome-genius.c b/src/gnome-genius.c
index a4af9cc..1d2e345 100644
--- a/src/gnome-genius.c
+++ b/src/gnome-genius.c
@@ -3454,7 +3454,7 @@ file_is_writable (const char *fname)
static void
new_program (const char *filename, gboolean example)
{
- char *contents;
+ char *contents = NULL;
static int cnt = 1;
GtkWidget *tv;
GtkWidget *sw;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]