# Reprezentation of large numbers in cryptographical application

**URL:** <https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522>\
**Category:** New to Julia\
**Created:** [January 22, 2018, 11:44am UTC](https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522 "2018-01-22T11:44:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![majzlik](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@majzlik](https://discourse.julialang.org/u/majzlik)\
**Post date:** [January 22, 2018, 11:44am UTC](https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522/1 "2018-01-22T11:44:36Z")

</div>

Hi,  
I would like to ask you, how I should work with large numbers. I need to generate number bigger than 2^160 a work with it bit by bit and then hash it. I searched for some information but I’ve found only main data types and data structures. Is there any structure or data type to represent such a large number and work with it?  
Thanks

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 22, 2018, 11:45am UTC](https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522/2 "2018-01-22T11:45:45Z")

</div>

`BigInt` is probably what you need:

[https://docs.julialang.org/en/stable/manual/integers-and-floating-point-numbers/#Arbitrary-Precision-Arithmetic-1](https://docs.julialang.org/en/stable/manual/integers-and-floating-point-numbers/#Arbitrary-Precision-Arithmetic-1)

---

<div class="post-metadata">

**Author:** ![majzlik](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@majzlik](https://discourse.julialang.org/u/majzlik)\
**Post date:** [January 22, 2018, 2:10pm UTC](https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522/3 "2018-01-22T14:10:28Z")

</div>

I’m trying to create number 2^160 using:

```julia
BigInt(2^160) => result 0

```

but I’m still limited by size of Int → 2^64 = 0, so I got result 0 for BigInt also. Everything alse works fine, I can sum or multiply number which cross that 2^64 border.

```julia
BigInt(2^62) ^ 2 => works
BigInt(2^124) => does not work

```

Did I miss anything?

---

<div class="post-metadata">

**Author:** ![Paethon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paethon/32/9278_2.png) [@Paethon](https://discourse.julialang.org/u/Paethon)\
**Post date:** [January 22, 2018, 2:14pm UTC](https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522/4 "2018-01-22T14:14:23Z")

</div>

> [@majzlik](#):
>
> BigInt(2^160)

The problem with this is, that 2^160 would have to be an Int before it is converted to a BigInt (which obviously does not work). So you can e.g. write big(2)^big(160)

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [January 22, 2018, 6:10pm UTC](https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522/5 "2018-01-22T18:10:55Z")

</div>

Please note that `BigInt` is in general not appropriate for production cryptographic implementations because the operations on it are not constant time, so you need to make sure not to expose side timing side channels.

---

<div class="post-metadata">

**Author:** ![majzlik](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@majzlik](https://discourse.julialang.org/u/majzlik)\
**Post date:** [January 23, 2018, 3:22pm UTC](https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522/6 "2018-01-23T15:22:38Z")

</div>

Is it only matter of time why it is not suitable? I’m working on elliptic curve generation according to this article:  
[1030\_Buchmann](https://www.ipa.go.jp/security/enc/CRYPTREC/fy15/doc/1030_Buchmann.evaluation.pdf)  
Then I’m gonna test a few algorithms to solve ECDLP, so I think that this issue is not connected to my work.

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [January 23, 2018, 3:25pm UTC](https://discourse.julialang.org/t/reprezentation-of-large-numbers-in-cryptographical-application/8522/7 "2018-01-23T15:25:27Z")

</div>

It’s just fine for doing cryptography research, all I wanted to point out is that writing secure implementations of real-world cryptographic protocols is more difficult than getting the math right, and BigInt is not suitable for that purpose.
