Thursday, May 29, 2014

How much time does it takes to scan the entire Internet?

One week?, One month?


Extracted from https://github.com/robertdavidgraham/masscan

"This is the fastest Internet port scanner. It can scan the entire Internet in under 6 minutes, transmitting 10 million packets per second."

All you need is some good idea to start hacking the Internet and a 10Gbit/s symmetric link. Just ask your local carrier about it.


Sunday, May 4, 2014

Spontaneus symetry breaking of prime numbers.



Let's imagine for a moment that we start adding "+1" for each natural number. Whenever we reach a prime number we switch the sum from "+1" to "-1".  If prime numbers are randomly distributed we expect the total sum to oscillate around 0.
Take for example the first 20 numbers (in bold prime numbers, where we start switching back):

                                        | Total
    3       3                           |
  2   2   2   2                         |
1       1       1       1               |
------------------0---0---0--------------
                   -1      -1      -1   |
                             -2  -2  -2 |
                               -3       |
                                        |
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 |
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
    *   *   *       *   *       *   *   |



 Let's see what we get in practice.


Next python code simulate the previous process/algorithm/"thing":


  1 def isprime(n):
  2     n*=1.0
  3     if n%2==0 and n!=2 or n%3==0 and n!=3:
  4         return False
  5     for b in range(1,int((n**0.5+1)/6.0+1)):
  6         if n%(6*b-1)==0:
  7             return False
  8         if n %(6*b+1)==0:
  9            return False
 10     return True
 11
 12 START=1
 13 total=0
 14 sum = -1
 15 for END in xrange(5000000,30000001,5000000):
 16     totalNeg=0
 17     totalPos=0
 18        
 19     for i in xrange(START, END):
 20         total = total + sum
 21         if total > 0:
 22             totalPos += 1
 23         if total < 0:
 24             totalNeg += 1
 25         if isprime(i):
 26             sum  = -1 * sum
 27     START = END+1
 28    
 29     rat = totalPos*1./totalNeg
 30     if rat > 1:
 31        rat = 1./rat
 32     
 33     print total, total*1./END, totalPos, totalNeg, rat


Every 5000000 numbers we print some statistics (line 33).



In the program output, the first column prints the "total" variable, which shows the total sum at a given time. We expect such column to be evenly distributed between negative and positive numbers. The second column shows the ratio between the total sum and the current natural number, that we expect to be close to zero. The third column will show how many times the total sum was possitive, with the fourth column showing how many times it was negative, finally the fith column shows the ratio between the times the total sum was possitive and the time it was negative. We expect column 3 to be quite similar to column 4, and so fith column close to 1.


Let's see what our program shows in practice:

SUM    Current / SUM    
-1757  -0.00292833333333 90292  509554 0.177198

-3393  -0.00308454545455 90292 1009554 0.089437
-6197  -0.003873125      90292 1509554 0.059813
-9685  -0.0046119047619  90292 2009554 0.044931
-10401 -0.00400038461538 90292 2509554 0.035979


Not exactly the result I was waiting for. Intuition failed (as is always the case with prime numbers). The sum never oscillates and cross back to zero creating what scientifics will call an spontaneous break of symmetry.



Saturday, May 3, 2014

C++ or C--?


Copy&Paste from "Expert C programming, Deep secrets":

"If you think C++ is not overly complicated, just what is a protected abstract virtual base pure virtual private destructor, and when was the last time you needed one?"

In the mean time C is a great language with all its "buts" !

Update: 2015-03
Defective C++ is worth reading before adventuring into the C-- nightmare.