Announcements

Getting in touch with your instructor...

Useful Resources

LaTeX Fun

You can exchange the commands in the box below for your own and render it on demand. It's kind of fun! Press the Render! button when you're ready.

Let’s roll that beautiful math footage!

\({}\)

SageMath and Tiny SageMath Programs

SageMath is free open source mathematics software that can do some pretty amazing calculations, and the software has a ton of useful libraries and built-in functions. You can download and install Sage for use on your computer through a terminal window or Juypter notebook, or you can use Sage online through CoCalc or SageMathCell. The SageMath language is built on Python, so if you know a bit of Python then you can often logic your way around SageMath. I will often use SageMathCell in class for quick examples and calculations but I prefer to use SageMath in a Juypter notebook on my computer so you might see both during the class meetings.

For really quick things, here's a SageCell box that you can try out! Change the input area to be whatever code you need, press Evaluate, and ta da!

You may prefer a different language or different software and that's great! Go ahead and use whatever you wish that will complete the same operations. SageMath has a lot of built-in programs and functions that make the programming easier, but there's something to be said for figuring out how to get the same results yourself and for learning how to do the same computations in your preferred programming language.

A few good SageMath commands to know:

  • mod(x,n) returns the remainder of \(x\) modulo \(n\)
  • factor(n) factors \(n\) ... but this can time out if \(n\) is big and hard enough to factor
  • inverse_mod(x,n) calculates the inverse of \(x\) modulo \(n\)
  • power_mod(x,i,n) gives \(x^i\) modulo \(n\)
  • euler_phi(n) produces \(\varphi(n)\), the Euler totient of \(n\)
  • g=mod(primitive_root(p),p) instructs Sage to select a primitive root modulo \(p\) and call it \(g\)
  • p= random_prime(a, True) will return a random prime between 2 and \(a\)
  • CRT_list([a1,a2,...,ak],[m1,m2,...,mk]) will solve a system of linear congruences, \(\{x \equiv a_1 \textrm{ mod } m_i \mid 1 \leq i \leq k\}\), provided that the moduli are pairwise relatively prime
  • Mod(x,p).nth_root(n,all=True) asks Sage to produce a list of all remainders modulo \(p\) that, when squared, produce \(x\)
  • Mod(x,p).sqrt(all=True) asks for all square roots of \(x\) modulo \(p\)

Tiny SageMath Programs

I've gathered several small bits of code that have been helpful in previous iterations of Cryptology. You can copy the code and paste it into the SageCell here, or on the SageMathCell site, to test it out. This is not organized in a reasonable way, and much of it is not explained ... explanations and elaborations will happen in class, so take good notes. Worst of all, some of this needs to be updated to match SageMath's current standards!

The Base 27 Code: Encoding

This bit of code will correctly handle phrases that are in lower-case and have no spaces. Evaluate the function and then call the function on a Python string; for example b27en('elizabeth') should return 2470610206256.


def b27en(str):
    result = 0
    nums = []
    for i in [0..len(str)-1]:
        castToNumber = ord(str[i]) - 96
        nums.append(castToNumber)
        result = result + castToNumber*(27^i)
    return result