You are on page 1of 30

Highlights of Computing: From the

Ancient Indian Vedic Literature to


Modern Practical Cryptography
Uwe Wystup

uwe.wystup@mathfinance.com

February 2010

1
Uwe Wystup - Highlights of Computing 2

Contents
1 Numeral Systems 3
1.1 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Vedic Mathematics 4
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.1 The 16 Sutras . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.2 Jagadguru Swami Sri Bharati Krsna Tirthaji Maharaja 6
2.2 Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4 Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.5 Divisibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.5.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.6 Square Roots (Vargamula) . . . . . . . . . . . . . . . . . . . . 14
2.6.1 Duplex Process (Dvandvayoga) . . . . . . . . . . . . . 15
2.6.2 Square Root of a Perfect Square . . . . . . . . . . . . . 15
2.6.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3 Zero Search Methods 17


3.1 Newton’s Method . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.1.1 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1.2 Rate of Convergence . . . . . . . . . . . . . . . . . . . 20
3.2 Heron’s Square Root Finder . . . . . . . . . . . . . . . . . . . 21
3.3 Exercise: Divisions without Dividing . . . . . . . . . . . . . . 21

4 Credit Cards 21
4.1 The Luhn Algorithm . . . . . . . . . . . . . . . . . . . . . . . 22
4.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

5 Cryptography 24
5.1 The Inventors of the RSA-Algorithm (1978) . . . . . . . . . . 24
5.2 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.4 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6 Definitions 28
6.1 Prime Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6.2 Modulus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Uwe Wystup - Highlights of Computing 3

7 Contact Information 29

1. Numeral Systems

2. Vedic Mathematics

3. Zero Search Methods

4. Credit Cards

5. Cryptography

6. Definitions

1 Numeral Systems
• Fundamentals: Any integer has a unique representation as a weighted
sum of powers of a chosen base.

• Example: 245 = 2 · 102 + 4 · 101 + 5 · 100

The Base 10 is in no way special except that

• The Mayas also used the feet (base=20), see http://en.wikipedia.org/


wiki/Maya_numerals.

• Computers use a dual system (power off or on, base 2) or a hexadecimal


system (0, 1, 2, . . . , 9, A, B, C, D, E, F ) for memory size: 1 byte = F F .

• More on http://en.wikipedia.org/wiki/Numeral_system

1.1 Exercise
Write the hexadecimal number CAF E in the dual, decimal and Maya number
system.
Uwe Wystup - Highlights of Computing 4

2 Vedic Mathematics
1. Introduction

2. Multiplication

3. Squares

4. Division

5. Divisibility

6. Square Roots

2.1 Introduction
veda (Sanskrit) means: knowledge

Veda Upaveda

Rigveda Ayurveda
Samaveda Gandharvaveda
Yajurveda Dhanurveda
Atharvaveda Sthapatyaveda

Table 1: Vedas and Upavedas (supplementary vedas)


Uwe Wystup - Highlights of Computing 5

2.1.1 The 16 Sutras


are part of a Parisista (Appendix) of the Atharvaveda

1. By one more than the one before

2. All from 9 and the last from 10

3. Vertically and crosswise

4. Transpose and apply

5. If the Samuccaya is the same it is zero

6. If one is in ratio the other is zero

7. By addition and by subtraction

8. By the completion or non-completion

9. Differential calculus

10. By the deficiency

11. Specific and general

12. The remainders by the last digit

13. The ultimate and twice the penultimate

14. By one less than the one before

15. The product of the sum

16. All the multipliers


Uwe Wystup - Highlights of Computing 6

2.1.2 Jagadguru Swami Sri Bharati Krsna Tirthaji Maharaja


Explained the sutras in his books.

Jagadguru Swami Sri Bharati Krsna


Tirthaji Maharaja (March, 1884 -
February 2, 1960) was the Jagadguru
(literally, teacher of the world; assigned
to heads of Hindu mathas) of the Go-
vardhana matha of Puri during 1925-
1960. He was one of the most signifi-
cant spiritual figures in Hinduism dur-
ing the 20th century. He is particularly
known for his work on Vedic mathemat-
ics.

2.2 Multiplication
Example with working base 10:

9 - 1 7 - 3 13 + 3 12 + 2
× × × ×
7 - 3 6 - 4 12 + 2 8 - 2
6 / 3 3 /1 2 15 / 6 10 / 4̄
= 63 = 42 = 156 = 96

Reason: (x + a)(x + b) = x(x + a + b) + ab


Origin of the ×-sign comes from this method
Uwe Wystup - Highlights of Computing 7

Example with working base 100:

91 - 9 111 + 11 108 + 8
× × ×
96 - 4 109 + 9 97 - 3
87 / 36 120 / 99 105 / ¯
24
= 8736 = 12099 = 10476

Other working bases (division case)

100/2=50 100/2=50
49 - 1 54 + 4
× ×
49 - 1 46 - 4
2)48 / 01 2)50 / 1̄6̄
24 / 01 25 / 1̄6̄
= 2401 = 2484

Other working bases (multiplication case)

10× 2=20 10× 6=60


19 - 1 62 + 2
× ×
19 - 1 48 - 12
× 2)18 / 1 × 6)50 /2̄ 4̄
36 / 1 300 /2̄ 4̄
= 361 = 2976
Uwe Wystup - Highlights of Computing 8

2.2.1 Exercises
Multiply the following

a 94 × 94

b 97 × 89

c 87 × 99

d 87 × 98

e 87 × 95

f 95 × 95

g 79 × 96

h 98 × 96

i 92 × 99

j 88 × 88

k 97 × 56

l 97 × 63

m 92 × 196
Uwe Wystup - Highlights of Computing 9

Multiply the following mentally

a 667 × 998

b 768 × 997

c 989 × 998

d 885 × 997

e 883 × 998

f 8×6

g 891 × 989

h 8888 × 9996

i 6999 × 9997

j 90909 × 99994

k 78989 × 99997

l 9876 × 9989
Uwe Wystup - Highlights of Computing 10

Multiply the following mentally

a 133 × 103

b 107 × 108

c 171 × 101

d 102 × 104

e 132 × 102

f 14 × 12

g 18 × 13

h 1222 × 1003

i 1051 × 1007

j 15111 × 10003

k 125 × 105

l 10607 × 10008

2.3 Squares
Using the sutra Ekadhikena Purvena (“by one more than the previous one”) we
get

152 = 1 × 2/25 = 2/25 = 225


252 = 2 × 3/25 = 6/25 = 625
352 = 3 × 4/25 = 12/25 = 1225
..
.
2
115 = 11 × 12/25 = 132/25 = 13225
Uwe Wystup - Highlights of Computing 11

2.3.1 Exercises
Multiply the following mentally

a 652

b 852

c 0.52

d 7.52

e 0.02252

f 10502

g 1752

2.4 Division
• Lots of tricks are available. We do only some highlights.
1
• Find the exact decimal representation of 19
.

• Standard methods are cumbersome.

• Using the “Ekadhika Purva” Sutra it is easy:

• Start with 1 and then work from right to left multiplying by 2.

. 0 5 2 6 3 1 5 7 8 / 9 4 7 3 6 8 4 2 1
1 1 1 1 1 1 1 1 1
Uwe Wystup - Highlights of Computing 12

• A further shortcut is the insight that

. 0 5 2 6 3 1 5 7 8
+ 9 4 7 3 6 8 4 2 1
= 9 9 9 9 9 9 9 9 9

1
• The same works for all periodic decimals, e.g. 7

. 1 4 2
+ 8 5 7
= 9 9 9

2.4.1 Exercises
Compute the exact decimal number of
1
a 29
1
b 49
Uwe Wystup - Highlights of Computing 13

2.5 Divisibility
• Use Ekadhika as an osculator.

• For 9, 19, 29, 39 etc. the Ekadhikas are 1, 2, 3, 4, etc.

• For 3, 13, 23, 33 etc. multiply them by 3 and you get 1, 4, 7, 10, etc. as
the Ekadhikas.

• For 7, 17, 27, 37 etc. multiply them by 7 and you get 5, 12, 19, 26, etc.
as the Ekadhikas.

• For 1, 11, 21, 31 etc. multiply them by 9 and you get 1, 10, 19, 28, etc.
as the Ekadhikas.

• Now test if 112 is divisible by 7 osculating by 5: 2 × 5 + 11 = 21, which


is divisible by 7.

• Therefore: yes

Is 2774 divisible by 19? Osculate by 2:

2 7 7 4
+ 8
2 8 5
+ 1 0
3 8
+ 1 6
1 9
Uwe Wystup - Highlights of Computing 14

• One more example: Is 5293240096 divisible by 139?

• The Ekadhika (osculator) is 14.

5 2 9 3 2 4 0 0 9 6
139 89 36 131 29 131 19 51 93

• Answer: yes

2.5.1 Exercises
Using the osculation method, check if

a 32896 is divisible by 29

b 93148 is divisible by 29

c 4914 is divisible by 39

d 14061 is divisible by 43

2.6 Square Roots (Vargamula)


• 1, 5, 6 and 0 at the end of a number reproduce themselves as the last
digits in the square.

• Squares of complements from 10 have the same last digit; thus 12 and 92
end in 1, 22 and 82 end in 4 etc.

• 2, 3, 7 and 8 are out of court altogether.


n
• If the given number has n digits, then the square root will contain 2
or
n+1
2
digits.

• Systematic computation of an exact square root requires the Dvandvayoga


(Duplex) process.
Uwe Wystup - Highlights of Computing 15

2.6.1 Duplex Process (Dvandvayoga)

D(4) = 42 = 16 (1)
D(43) = 2 · 4 · 3 = 24 (2)
D(137) = 2 · 1 · 7 + 32 = 23 (3)
D(1034) = 2·1·4+2·0·3=8 (4)
D(10345) = 2 · 1 · 5 + 2 · 0 · 4 + 32 = 19 (5)

Got it?

2.6.2 Square Root of a Perfect Square



Find 1849.

Group in pairs, taking a single extra digit on the left as extra digit.

1 8 — 4 9
8) 2
4

4 is the largest integer whose square does not exceed 18.


18/4 is 4 with remainder 2.
The divisor 8 is two times 4.

Next we divide 24 by the divisor 8. This gives 3 remainder 0, placed as

1 8 — 4 9
8) 2 0
4 3

Now we see 09 and we deduct from this the duplex of the last answer figure 3,
i.e. 09 − D(3) = 09 − 32 = 09 − 9 = 0. This means that the answer is exactly
43.
Uwe Wystup - Highlights of Computing 16

1 3 — 6 9
6) 4
3

3 is the largest integer whose square does not exceed 13.


13/3 is 3 with remainder 4.
The divisor 6 is two times 3.
Next we divide 46 by the divisor 6. This gives 7 remainder 4, placed as

1 3 — 6 9
6) 4 4
3 7

49 − D(7) = 0, so 37 is the exact square root of 1369.


Uwe Wystup - Highlights of Computing 17

2.6.3 Exercises
Find the square root of the following.

a 3136

b 3969

c 5184

d 3721

e 6889

f 1296

Find out how the method extends to 6-digit squares and find the square roof
of the numbers

a 119025

b 524176

c 519841

d 375769

3 Zero Search Methods


1. Newton’s Method

2. Heron’s Square Root Finder

3. Exercise: Divisions without Dividing


Uwe Wystup - Highlights of Computing 18

Sir Isaac Newton


1643 - 1727

3.1 Newton’s Method


Given a differentiable function f (x) we want to determine x̂ such that

f (x̂) = 0. (6)

Starting with x0 we take the tangent to the curve through the point (x0 , f (x0 ))
and use its intersection with the x-axis x1 as a new starting point. We repeat
this method until no further changes occur. The recursive relation is

f (xn )
xn+1 = xn − (7)
f 0 (xn )

and the result is

lim xn = x̂. (8)


n→∞
Uwe Wystup - Highlights of Computing 19

Newton’s Method - graphically

3.1.1 Problems
Problems can occur due to

1. multiple solutions

2. non convex f , reflection points

3. solutions at extreme values

4. |f 0 | = ∞

5. pathological cases
Uwe Wystup - Highlights of Computing 20

3.1.2 Rate of Convergence


Considering all these problems, why is Newton’s method still so popular? The
reason lies in the rate of convergence. Define the error by

en = xn − x̂ (9)

From the definition of the Newton iteration, we have

en+1 = xn+1 − x̂
f (xn )
= xn − 0 − x̂
f (xn )
f (xn )
= en − 0
f (xn )
0
en f (xn ) − f (xn )
= (10)
f 0 (xn )

By Taylor’s Theorem, we have

0 = f (x̂) = f (xn − en ) (11)


1
= f (xn ) − en f 0 (xn ) + e2n f 00 (ξn ) (12)
2
where ξn is a number between xn and x̂. A rearrangement of this equation
yields
1
en f 0 (xn ) − f (xn ) = f 00 (ξn )e2n (13)
2
Putting this in (10) leads to

1 f 00 (ξn ) 2 1 f 00 (x̂) 2
en+1 = 0
e n ≈ 0
en = Ce2n (14)
2 f (xn ) 2 f (x̂)

This equation tells us that en+1 is roughly a constant times e2n . This desirable
state of affairs is called quadratic convergence.
Uwe Wystup - Highlights of Computing 21

3.2 Heron’s Square Root Finder


• Goldman Sachs standard interview question: Find the square root of 17.

• The Greek Engineer Heron who lived sometime between 100 B.C. and 100
A.D. had used the recursion
 
1 R
xn+1 = xn + (15)
2 xn

to find the square root of R.

• This is based on Newton’s method.

• Taking R = 17 and starting with x0 = 4 we find x4 =


4.123105625617660549821409856 which is correct to 28 figures.

3.3 Exercise: Divisions without Dividing


• Use Newton’s method to determine an algorithm that computes the re-
ciprocal of a given number x, without ever performing any division.
1
• apply your method to compute 19
exact to 8 decimal places.

4 Credit Cards
We follow An Introduction to the Mathematics of Money by Lovelock, Mendel
and Wright [3].


9876
|{z} 5432
| 1987
{z 654} |{z}
3 (16)
BIN cardholder ID checksum
• BIN: Bank Identification Number

• More on http://en.wikipedia.org/wiki/Credit_card_numbers

• checksum: designed to protect against accidental errors, not malicious


attacks. How?

• Luhn algorithm
Uwe Wystup - Highlights of Computing 22

4.1 The Luhn Algorithm

Hans Peter Luhn

The Luhn algorithm or Luhn formula, also known as the modulus 10 or mod
10 algorithm, is a simple checksum formula used to validate a variety of
identification numbers, such as credit card numbers and Canadian Social
Insurance Numbers.

It was created by IBM scientist Hans Peter Luhn and described in US Patent
2,950,048, filed on January 6, 1954, and granted on August 23, 1960.
Uwe Wystup - Highlights of Computing 23

9876
|{z} 5432
| 1987
{z 654} |{z}
3
BIN cardholder ID checksum

9 8 7 6 5 4 3 2 1

×2 ↓ ×2 ↓ ×2 ↓ ×2 ↓ ×2 ↓
18 8 14 6 10 4 6 2 2

9 8 7 6 5 4 add up

×2 ↓ ×2 ↓ ×2 ↓ digits
9 16 7 12 5 8 82

Table 2: Example of the Luhn Algorithm

Note: 18 counts as 1 + 8, i.e. count only the digits

9876
|{z} 5432
| 1987
{z 654} |{z}
3
BIN cardholder ID checksum
• Add the checksum 3 to the 82 and obtain 85.

• If the new total is divisible by 10, then the credit card number has passed
the validation test.

• our number fails, whereas

9876
|{z} 5432
| 1987
{z 654} |{z}
8
BIN cardholder ID checksum
passes.

• Note: Amex has one digit less and starts with the second digit.
Uwe Wystup - Highlights of Computing 24

4.2 Exercises
1. Implement the Luhn-Algorithm in Excel.

2. Apply the Luhn-Algorithm to your own credit card number.

3. In your group think of a credit card number and ask another group to
verify it.

4. Does the Luhn Algorithm pick up any incorrect entry of a single digit?

5. Will the Luhn Algorithm pick up any incorrect transposition of adjacent


digits?

5 Cryptography
1. The Inventors of the RSA-Algorithm

2. Method

3. Examples

4. Exercise

5.1 The Inventors of the RSA-Algorithm (1978)


Ron Rivest, Adi Shamir, and Leonard Adleman [5]
Uwe Wystup - Highlights of Computing 25

Ronald L. Rivest
Andrew and Erna Viterbi Professor of Electrical Engineering and Computer
Science in MIT’s Department of Electrical Engineering and Computer Science

http://theory.lcs.mit.edu/~rivest/

Adi Shamir
Paul and Marlene Borman Professor of Applied Mathematics at Weizmann
Institute

http://www.weizmann.ac.il/math/profile04/scientists/
shamir-prof04.html
Uwe Wystup - Highlights of Computing 26

Professor Leonard Adleman


Department of Computer Science University of Southern California

http://www.usc.edu/dept/molecular-science/fm-adleman.htm

5.2 Method
We follow Francis Litterio’ instructions on http://world.std.com/~franl/
crypto/rsa-guts.html.

1. Find P and Q, two large (e.g., 1024-bit) prime numbers.

2. Choose E ∈]1, P Q[, no prime factors in common with (P − 1)(Q − 1).

3. Compute D (the multiplicative inverse) such that DE = 1 mod (P −


1)(Q − 1). (Find an integer X which causes D = (X(P − 1)(Q − 1) + 1)/E
to be an integer, then use that value of D.)

4. The encryption function is C = T E mod P Q, where C is the ciphertext


(a positive integer), T is the plaintext (a positive integer). The message
being encrypted, T , must be less than the modulus, P Q.

5. The decryption function is T = C D mod P Q, where C is the ciphertext


(a positive integer), T is the plaintext (a positive integer).
Uwe Wystup - Highlights of Computing 27

Your public key is the pair (P Q, E). Your private key is the number D
(reveal it to no one). The product P Q is the modulus (often called N in the
literature). E is the public exponent. D is the secret exponent.

You can publish your public key freely, because there are no known easy meth-
ods of calculating D, P , or Q given only (P Q, E) (your public key). If P
and Q are each 1024 bits long, the sun will burn out before the most powerful
computers presently in existence can factor your modulus into P and Q.

5.3 Examples
prime 1 P 5 11 37 61
prime 2 Q 7 7 41 53
public modulus N = PQ 35 77 1517 3233
P −1 4 10 36 60
Q−1 6 6 40 52
(P − 1)(Q − 1) 24 60 1440 3120
public exponent E 5 7 7 17
inverse of E D 5 43 823 2753
check DE 25 301 5761 46801
check DE − 1 24 300 5760 46800
check [DE − 1]/[(P − 1)(Q − 1)] 0 0 0 0
plaintext T 5 6 100 123
encryption function C = T E mod P Q 10 41 1062 855
decryption function T = C D mod P Q 5 6 100 123
Uwe Wystup - Highlights of Computing 28

5.4 Exercise
1. Set up an RSA tool in Excel/VBA and verify the examples.

2. Take two prime numbers P and Q between 100 and 200, e.g. from http:
//primes.utm.edu and compute E and D.

3. Based on a plain text of your choice compute its ciphertext.

4. Give your public key and the ciphertext to the next group and determine
the plaintext of another group.

6 Definitions
6.1 Prime Numbers
a number that can only be divided evenly by 1 and the number itself.

6.2 Modulus
For integers K, R and N the equation

K = R mod N (17)

means that R is the remainder of the division of K by N or alternatively there


exists an integer L such that

N · L + R = K. (18)
Uwe Wystup - Highlights of Computing 29

7 Contact Information
Professor Dr. Uwe Wystup
Ansua Dutta-Wystup
Managing Directors

MathFinance AG
Mainluststraße 4
60329 Frankfurt am Main
Germany
Phone +49-700-MATHFINANCE
More papers are available at
http://www.mathfinance.com/wystup/papers.php
These slides and handouts are available at
http://www.mathfinance.com/seminars/vedic.php

References
[1] Burden, R. L. and Faires, J. D. (1993). Numerical analysis. PWS
Publishing Company.

[2] Datta, B. and Singh, A.N. (1962). History of Hindu Mathematics.


Asia Publishing House, Calcutta.

[3] Lovelock, D., Mendel, M. and Wright, A.L. (2007). An Introduc-


tion to the Mathematics of Money, Springer, New York.

[4] Maharaja, Bharati Krsna Tirthaji (1992). Vedic Mathematics, Motilal


Banarsidass Publishers Private Ltd, Delhi.

[5] Rivest, R.L., Shamir, A. and Adleman, L.M. (1978). A Method for
Obtaining Digital Signatures and Public-Key Cryptosystems. Commu-
nications of the ACM 21,2, 120–126.

[6] Schonard, A. and Kokot, C. (2006). Der Matheknüller. http://www.


matheknueller.de.

[7] Williams, K.R. (2002). Vedic Mathematics - Teacher’s Manual. Ad-


vanced Level. Motilal Banarsidass Publishers Private Limited, Delhi.
http://www.mlbd.com
Index
bank identification number (BIN), 21
BIN, 21

division, 11, 13
dual system, 3
duplex, 15
dvandvayoga, 15

ekadhika, 13

Heron’s Square Root Finder, 21


hexadecimal system, 3

Luhn algorithm, 22

Maya numerals, 3
modulus, 28
multiplication, 6

Newton’s Method, 18
numeral systems, 3

osculator, 13

prime number, 28

quadratic convergence, 20

RSA-Algorithm, 24

square root, 14
squares, 10
sutras, 5

vedas, 4

30

You might also like