It was brought up a while back in a Community Call to Arms that *math* is handy for encryption (and let's face it, everything) so let us go over things you just have to know. "In its simplest meaning in mathematics and logic, an operation is an action or procedure which produces a new value from one or more input values."[source]

To provide tech. related examples, I will give brief lines of Haskell code copied out of GHCI (my Haskell compiler of choice run live). Haskell is a pure functional language I really enjoy and you can read more about here.

## Simple Math

The stuff you learned about in grade school.

**Addition; +**

Addition is one of the building blocks of mathematics. The intricacies of basic addition are more to do with the naming involved in number systems in general. "Addition is a mathematical operation that represents combining collections of objects together into a larger collection:"[source]. Addition is normally taught in the decimal system, as that is the current standard for math done by humans by hand but the principals apply for all number systems.

H+> [0..19]

[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]

H+> 0 + 1

1

H+> 3 + 2

5

H+> 6 + 9

15

H+> 10 + 9

19

H+> 0 + 3 + 10 + 6

19

I won't go much farther than that unless requested.

**Subtraction; -**

Addition with negative values. Sometimes subtraction is described as "the opposite of addition" and while not exactly true, it can accurately be described as the removal of elements from a set. Hopefully the examples sort out any confusion.

H+> 19 - 9

10

H+> 19 - 10 - 6

3

H+> 10 - 9

1

H+> 9 - 6

3

H+> 3 - 2

1

H+> 1 - 0

1

H+> 0 - 1

-1

H+> 9 - 19

-10

H+> 3 + (-2)

1

H+> (-3) + 2

-1

**Multiplication; x (*)**

Multiplication "is the mathematical operation of scaling one number by another"[source]. I once thought of it as "repeated addition". Aka, 3 x 4 = 3 + 3 + 3 + 3 = 12, so 3 x 4 is 3 added together 4 times. Sometimes this is said aloud to be "Three times four." This concept includes negative numbers, (-3) x 4 = (-12), 3 x (-4) = (-12), while (-3) x (-4) = 12. The single negative is moderatly confusing, but could follow the same trend as before ((-3) x 4 = (-12), (-3) + (-3) + (-3) + (-3) = (-12)), but the double negative could be a little confusing. That would be seen more as (0 - (-3) - (-3) - (-3) - (-3) = 12) and I will leave you to puzzle at that. Examples follow.

H+> 1 * 3

3

H+> 0 * 7

0

H+> 3 * 4

12

H+> 5 * (-3)

-15

H+> (1 + 5) * (7 - 3)

24

H+> (1 * 7) + (1 * (-3)) + (5 * 7) + (5 * (-3))

24

**Division; ÷ (/)**

"Conceptually, division describes two distinct but related settings. Partitioning involves taking a set of size a and forming b groups that are equal in size. The size of each group formed, c, is the quotient of a and b. Quotative division involves taking a set of size a and forming groups of size b"[source]. Division and fractions are often (and really are) linked, however division is an operation and falls into the range of this post, while fractions do not. Division is intrinsically linked to another operation in this post. Division is often referred to as "the opposite of multiplication". Division of two strictly integer values may lead to a remainder (leftover) integer value. It works something like this: You have three friends over. The 4 of you buy a pizza. The pizza has 12 slices. The pizza costs 29 dollars. Splitting the pizza evenly you get 3 slices each (12 ÷ 4 = 3) , you each have to pay 7.25 (29 ÷ 4 = 7.25) or if none of you have change less than one dollar, three of you give 7 dollars and one of you gives 8 (29 ÷ 4 = 7 remainder 1).

H+>

4/31.3333333333333333

H+> 7/2

3.5

H+> 11/5

2.2

H+> 8/4

2.0

H+> 8/2

4.0

H+> 20/2

10.0

H+> 20/10

2.0

H+> -4/6

-0.6666666666666666

H+> (-7)/(-3)

2.333333333333333

If anything is unclear, just ask. I or some one else will surely answer.

## Intermediate Math

The stuff you learned about in high school.

**Exponents;**** (b ^ n) (b ** n)**

Normally written as b `superscript` n but that function does not seem to be supported here.

If you found "repeated addition" to be an apt description of multiplication, then exponents or "exponentiation" can easily be thought of at "repeated multiplication". (2 ^ 3 = [2 * 2 * 2 = (2 + 2) + (2 + 2) = 2 + 2 + 2 + 2] = 8) Exponentiation is an integral operation in many fields, including public key cryptography. [source]

H+> 2 ^ 3

8

H+> 2 ** 3

8.0

H+> 8 ^ 0

1

H+> 0 ^ 0

1

H+> 4 ^ 5

1024

H+> 8 ^ 2

64

H+> 2 ^ 8

256

H+> 3 ** 3

27.0

H+> (-3) ^ 2

9

H+> (-3) ^ 5

-243

There are a couple tricky ones in there. I will leave them to you to think over/look up/ask questions about.

**Dot and Cross product; · | × {respectively}**

I will not go into much depth regarding these operations but will go so far as to say they are most applicable when dealing with either complex numbers or vectors, are often used in physics and engineering (or at least multi-dimensional math). Dot product is given the formula

a · a = ||a||^2

a · b = ||a|| * ||b|| * cos(theta)

where a and b are vectors and theta (the greek letter theta) is the angle between their intersection. The formula for the cross product is given in a similar manner, and is

a × b = |a| * |b| sin(theta) * n

where a and b are vectors, theta is the angle between them, and n is a unit vector perpendicular to the plane containing a and b in the direction given by the right hand rule (silly, strange, but true). The image I wish to use seems to unavailable, but you can find it here.

Dot Product.

H+> let dotP a b = sum [ (a !! i) * (b !! i) | i <- [0..((min (length a) (length b)) - 1)]]

H+> dotP [1, 1] [1, 0]

1

H+> dotP [1, 3, -5] [4, -2, -1]

3

H+> dotP [4, 2, 1] [4, 2, 1]

21

H+> ((4^2) + (2^2) + (1^2))

21

I'll leave cross product blank for now.

## Somewhere Else:

**Modulus: (%)**

The modulus operator doesn't actually get talked about much in most of school, and yet it's underlying concepts do. It is finding solely the remainder of an integer division. In Haskell there is no infix modulus operator, but the standard is '%'. Haskell instead uses `mod` to do modulus.

H+> 1 `mod` 4

1

H+> 4 `mod` 2

0

H+> 2 `mod` 4

2

H+> 7 `mod` 3

1

H+> 11 `mod` 0

*** Exception: divide by zero

H+> 0 `mod` 11

0

H+> 9 `mod` 1

0

The modulus operator is very prevalent in programming contexts.

## Final Words

There shall be an Advanced Operations post to supplement this one, and of course there are many things not covered here. The intent here was to go over some of the more basic mathematic operators so that there was some communal starting place. I would rather have questions and discussion than simply explanation to a blank unanswering audience so please ask and discuss in the comments below. Math of all sorts is extremely useful, regardless of circumstance, but especially in programming and even more so in cryptographic applications.

Article image from http://www.bestesoft.com, all rights for it go to them. Kudos.

Shout out to Wikipedia for providing easy quotes.

**Want to start making money as a white hat hacker?** Jump-start your white-hat hacking career with our 2020 Premium Ethical Hacking Certification Training Bundle from the new Null Byte Shop and get over 60 hours of training from ethical hacking professionals.

## 1 Comment

Thanks for sharing Bird andBear, must've taken a while to write :)

## Share Your Thoughts