Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

RSA Numbers

JohnNichols
Valued Contributor III
2,656 Views

I am a bit lost. 

The RSA standard defines a block - I assume it can hold numbers as shown on 

https://en.wikipedia.org/wiki/ASN.1 

 

A picture of the format is shown below:

Screenshot 2021-12-30 180611.png

I am trying to work out what is the largest integer available in this format string? 

I think I am looking at a 14 digit number? But I am not sure?

Anyone ever worked with this format?  

0 Kudos
25 Replies
Neels
New Contributor II
1,077 Views
0 Kudos
JohnNichols
Valued Contributor III
994 Views

Ignorance, thank you - I will change the code. 

0 Kudos
jimdempseyatthecove
Honored Contributor III
965 Views

John,

Consider the following


! set = float(prime)/100.0	! effectively shift right two decimal places
!                               ! *** 1.0/100. does not produce an exact binary fraction
! setL = floor(set)		! keep the integer part
! set = (set-setL) * 100	! produce what were the least significant two digits of prime
! replace the above with
set = mod(prime, 100)

And then consider removing the silliness of using floating point numbers.

Note, line 2 can (will at times) produce an inexact result and thus resulting in line 5 producing the incorrect value.

Jim Dempsey

0 Kudos
JohnNichols
Valued Contributor III
438 Views

Thanks for the idea, I should have thought of it, but that is the beauty of peer review, it keeps you modest, maybe.  

I fixed the code although it is running at the moment to do 10 million primes. 

 

 

do while(flag ==0)
        read(file1,*, err = 200, end = 200)numb,ind
        cnt = cnt + 1
11      format(i2,1x,i1)
        if(ind == 0) then
            prime = numb
            flag = 1
            ind = 1
            set = mod(prime, 100)
            if( set >= 0 .and. set < 100) then
                nums(set) = nums(set) + 1
            end if

        end if
   
        
            write(file3,10)numb,ind
10          format(i0,1x,i0)
        
    end do

 

 

My daughter wanted to go shopping in Houston today with her friend.  We are passing a building with a big number sign in red, 3033, she said I like the sign, I said it is not prime and I only like prime numbers,  she said three factors, 3, 9 and 1011, I was surprised and said nine, not likely.  High school maths teaches a lot these days.  "But she was correct, 9 and 337. 

There is a significant speed difference between debug ifort and release ifx.  

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
425 Views

Should numb (aka prime) always be .ge. 0 then mod(prime, 100) will always be .ge. 0, then the if test will always be true. IOW lines 10&12 are unneeded.

Jim Dempsey

0 Kudos
Reply