Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AmarnathCJD/gogram
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Feb 7, 2024
2 parents 3572791 + f3a051f commit a3ce587
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
41 changes: 41 additions & 0 deletions internal/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func DoRSAencrypt(block []byte, key *rsa.PublicKey) []byte {
// SplitPQ splits a number into two primes, while p1 < p2
// Part of diffie hellman's algorithm, how it works - no idea
func SplitPQ(pq *big.Int) (p1, p2 *big.Int) {
// Benchmark: Fac 15x faster than SplitPQ
return Fac(pq) // TODO: test extensively for fail cases
rndmax := big.NewInt(0).SetBit(big.NewInt(0), 64, 1)

what := big.NewInt(0).Set(pq)
Expand Down Expand Up @@ -127,3 +129,42 @@ func Xor(dst, src []byte) {
dst[i] ^= src[i]
}
}

// Fac splits a number into two primes, while p < q
// Part of diffie hellman's algorithm
// Uses Pollard's rho algorithm
func Fac(pq *big.Int) (p, q *big.Int) {
p = big.NewInt(0).Set(pq)
q = big.NewInt(1)

x := big.NewInt(2)
y := big.NewInt(2)
d := big.NewInt(1)

for d.Cmp(big.NewInt(1)) == 0 {
x = f(x, pq)
y = f(f(y, pq), pq)

temp := big.NewInt(0).Set(x)
temp.Sub(temp, y)
temp.Abs(temp)
d.GCD(nil, nil, temp, pq)
}

p.Set(d)
q.Div(pq, d)

if p.Cmp(q) == 1 {
p, q = q, p
}

return p, q
}

func f(x, n *big.Int) *big.Int {
result := big.NewInt(0).Set(x)
result.Mul(result, result)
result.Add(result, big.NewInt(1))
result.Mod(result, n)
return result
}
4 changes: 2 additions & 2 deletions telegram/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func NewCache(logLevel string) *CACHE {

// --------- Cache file Functions ---------
func (c *CACHE) WriteFile() {
c.Lock()
defer c.Unlock()
//c.Lock()
//defer c.Unlock() // necessary?

if c.file == nil {
var err error
Expand Down
2 changes: 1 addition & 1 deletion telegram/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ mediaTypeSwitch:
break
}
if a, ok := at.(*DocumentAttributeVideo); ok {
var duration = int64(getValue(a.Duration, int32(GetVideoDuration(fileName))).(int32))
var duration = int64(getValue(int32(a.Duration), int32(GetVideoDuration(fileName))).(int32))
if a.W == 0 || a.H == 0 {
w, h := GetVideoDimensions(fileName)
if w > 0 && h > 0 {
Expand Down
3 changes: 3 additions & 0 deletions telegram/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ func (c *Client) handleAlbum(message MessageObj) {
messages: []*NewMessage{packMessage(c, &message)},
groupedId: message.GroupedID,
}
if c.dispatcher.activeAlbums == nil {
c.dispatcher.activeAlbums = make(map[int64]*albumBox)
}
c.dispatcher.activeAlbums[message.GroupedID] = abox
go func() {
<-abox.waitExit
Expand Down

0 comments on commit a3ce587

Please sign in to comment.