[Edu-sig] Does edu-sig extend to Jython?

Kirby Urner urnerk@qwest.net
Sat, 3 Aug 2002 11:29:44 -0400


>From math.forum math-teach:

[6] Java bigInteger class:
    http://world.std.com/~reinhold/BigNumCalc.html
    http://java.sun.com/products/jdk/1.1/docs/api/java.math.BigInteger.html
    (note:  many computer languages have built-in big integer capabilities,
    including Python, Scheme and J).  Although Java is useful to learn,
    I advocate starting with an interpreted language with an interactive
    shell, moving to Java and/or C++ etc. from there.  Python is a 
    useful starting place, as Jython (Python implemented in Java) gives
    you access to the Java class hierarchy (more on that soon).

Full text:
http://www.mathforum.com/epigone/math-teach/swoystexzher

============================

Jython 2.1 on java1.4.0 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> from java.util import Random
>>> from java.math import BigInteger
>>> def getprime(bits=1024,certainty=100):
...    rnd = Random()
...    return BigInteger(bits,certainty,rnd)
...
>>> getprime()
1067722720141438416936329289263562925035919827052678321832681866990063551831478848783821605522120173
6810758438542124774962778293181664954075068528879431188671218617821416729983420767730160839601649102
7878857263718814234305416020293364487398387002390977394929459089980299322531800903440856855529607114
180383003

>>> getprime()
1635022550460085571394950585678011702182813484094648009782139177599579586182605830422264786759942806
6019544571783674607592559827973071614319273868858895160925422316661623514842803442153354380766931493
9242514490725373277904794746971911859355192254290778916168701651664990099347432156336759947584206104
118948493

>>> getprime()
15706222468499394013126985176537386112522449249758855356092634960514837608365322425798261607230541327
89581600957239025130461151581105193875191042660095633244943545323662018745303479566186530171082550165
31711741827949634958045834621953209681970713938226207782244603038171287845793911833631631265924892410
373287

>>> bigint = getprime()
>>> type(bigint)
<jclass org.python.core.PyJavaInstance at 10464309>
>>> bigint.floatValue()
Infinity
>>> bigint.isProbablePrime(99)
1
>>> bigint.isProbablePrime(100)
1

>>> bigint.pow(2)
214793268321532821588032256725613858449483467767599346997237912568050073085731530361161226
725695449134622769743890477430905392637048124102454975861838931014229255152730779852520534
254378200892173836345052779200400122433349130797672576059665755720489272089893954150124169
523901608928637574073289079575702579235625324740500238669587719886835908838641130320542845
578194705858533582910376157235151754487862211543516033122087730609216769159405204723344850
797077730939061275722013680290323910220972076841881318348356037709865572730712481257166680
40788211105810341358163047403420965747220457580382148416014744960379763788929

>>> c = bigint.toString()
>>> c
'146558271114779742269301322602100529404339825949953501568329885567000695069308802534706613
9041468129102794812323684613120434312882417587175479128356285499832976028096600983849374227
9122680205473294626276722594258350825671715818394020427154688565234068066088213224883990455
9424077012873102161456076093117316673'
>>> type(c)
<jclass org.python.core.PyString at 12556818>

>>> def getpubkey():
...     return getprime().multiply(getprime())
...
>>> getpubkey()
127133456493088279995776882752806725520417953316178756866731817439300154920002336273874812973
932018769546144576391745529354677995406208924278599998857560993300626991338228551502052810615
810760467669950222620774460378427571545522173710439024339715394303867361788519087423082692724
751114134332697560062232157681946561523101996375783766149719220687611858586527051123811845006
341374879830653553796763328516750433647605584361271831289770121536089641369031180740570946982
659204264071753670488187301082391699009142364892039468587514022324815769559211318637652948317
84031938596412373659538624251864114757452178888891855688569