Sunday, June 28, 2020

Ebay Phishing Email - We have a surprise for ebay

For the record, the eBay email is going around with subject 
We have a surprise for ebay 📣

This email tries to trick you into previewing the images below, and you may think that is safe, but is the catch. 

What to do?  Report them, goto bottom of page.


From :  Congratulation <N7aLJ@n7alj.us>

Subject :  We have a surprise for ebay 

Has A Big Surprise For You


Claim one of our free exclusive

reward offers (minimum value $90)

if you can't see the images below please , click here <---PHISHING LINK 






How to tell this is a Phishing email ?

  1. Check email address in full, if it's not from originating company then it's phishing.
  2. Hover over all links in email, if it's not from the  company's website then forget it.

  3. The best way is to look at message source, see below.

How to examine Email Message Source ?

Now lets look at message source
  1. Outlook.com->Actions->View Message Source. 
  2. Gmail.com->More (down arrow to top right)->Show original.
Check for suspicious links, anything that does not originate from apple.com.


Report Phishing Email (not as Spam)

  1. Outlook.com->Junk (at Top)->Phishing Scam
  2. Gmail.com->More (down-arrow to top right)->Report Phishing 

Report Phishing URLs at Google now 

If you have recievied this email take further action now by click these links

  1. https://www.google.com/safebrowsing/report_phish/


Report phishing at Microsoft and government agencies

  1. http://www.microsoft.com/security/online-privacy/phishing-faq.aspx

Saturday, June 27, 2020

Home Depot Phishing Email - Open Immediately

For the record, the Home Depot Phishing email is going around with subject Open Immediately



What to do?  Report them, goto bottom of page.


From : Hᴏᴍᴇ dᴇᴘᴏt <executive@rsm.nl>

Subject : Open Immediately

Last day to claim your free Reward!

We have a surprise for Home Depot Shoppers
HOME DEPOT Gift Card

Congratulations!
You have been selected to get an exclusive reward
To qualify for this special offer, simply complete our 30-

second marketing survey about your shopping experiences
Click OK to start

801 US Highway 1
North Palm Beach, FL 33408

You may unsubscribe at any time. Unsubscribe





How to tell this is a Phishing email ?

  1. Check email address in full, if it's not from originating company then it's phishing.
  2. Hover over all links in email, if it's not from the  company's website then forget it.

  3. The best way is to look at message source, see below.

How to examine Email Message Source ?

Now lets look at message source
  1. Outlook.com->Actions->View Message Source. 
  2. Gmail.com->More (down arrow to top right)->Show original.
Check for suspicious links, anything that does not originate from apple.com.


Report Phishing Email (not as Spam)

  1. Outlook.com->Junk (at Top)->Phishing Scam
  2. Gmail.com->More (down-arrow to top right)->Report Phishing 

Report Phishing URLs at Google now 

If you have recievied this email take further action now by click these links

  1. https://www.google.com/safebrowsing/report_phish/


Report phishing at Microsoft and government agencies

  1. http://www.microsoft.com/security/online-privacy/phishing-faq.aspx

Wednesday, June 24, 2020

Phishing Email Netflix with Subject Re: Update Monthly Subscription - We have cancellation your Subscription Plan on

For the record, the Netflix Phishing email is going around with subject Re: Update Monthly Subscription - We have cancellation your Subscription Plan on xx/xx/2020



What to do?  Report them, goto bottom of page.


From : Netflix <mnthlysubscriptions-mmbership.euxxxxx@msdnikcesocpid.com>

Subject : Re: Update Monthly Subscription - We have cancellation your Subscription Plan on xx/xx/2020. 

NETFLIX
Monthly Subscription Plan
Hi,

Sometimes, you need to check, change or fix a
subscription payment method.
This occurs when Netflix try to take a payment as
the monthly charge for subscription service.

To resolve these issues, please go to Netflix home

Netflix Homepage - PHISHING LINK - http://hostsnetid-
awlcs.newcoverlinksdir.reviews/xxxxxxxx

We are ready to help. Please visit the Help Center for
more information.
Best Regards,

Netflix International B.V.





How to tell this is a Phishing email ?

  1. Check email address in full, if it's not from originating company then it's phishing.
  2. Hover over all links in email, if it's not from the  company's website then forget it.

  3. The best way is to look at message source, see below.

How to examine Email Message Source ?

Now lets look at message source
  1. Outlook.com->Actions->View Message Source. 
  2. Gmail.com->More (down arrow to top right)->Show original.
Check for suspicious links, anything that does not originate from apple.com.


Report Phishing Email (not as Spam)

  1. Outlook.com->Junk (at Top)->Phishing Scam
  2. Gmail.com->More (down-arrow to top right)->Report Phishing 

Report Phishing URLs at Google now 

If you have recievied this email take further action now by click these links

  1. https://www.google.com/safebrowsing/report_phish/


Report phishing at Microsoft and government agencies

  1. http://www.microsoft.com/security/online-privacy/phishing-faq.aspx

Tuesday, June 23, 2020

C# - Fastest way to find a number/integer in a string

After an extensive review of getting a lead integer from a string, see my post here.

Here's the fastest way in C# to get the 1st integer in a string. This is not Unicode compliant, but works for English speaking populations using ASCII numerals 0-9.

Code

using System;
using System.Diagnostics;
using System.Text; 
using System.Text.RegularExpressions; 

public static class StringExtensions {
 
        /// <summary>
        /// Fastest way to to find 1st number in a string and convert it into an integer
        /// </summary>
        /// <param name="intStr"></param>
        /// <returns></returns>
        //  https://metadataconsulting.blogspot.com/2020/06/CSharp-Fastest-way-to-find-a-number-or-integer-in-a-string.html
        public static int GetFirstIntFast(this string intStr)
        {
 
            int sum = 0; //must be zero
            char[] n = intStr.ToCharArray(); //fastest way to index a string
            int idxFirstDigit = -1;  

            for (int i = 0; i < n.Length; i++)
            {
                if (n[i] >= 48 && n[i] <= 57)  //'0'=48 and '9'=57 get lead number only
                {
                    if (idxFirstDigit == -1) idxFirstDigit = i; 
                    int z = sum * 10 + (n[i] - 48);
                    if (z < 0) //we get into negative, if over int.MaxValue
                        return int.MaxValue; //or throw error
                    sum = z;
                }
                else if (idxFirstDigit>-1)
                    break;
                    //return int.MinValue; //or throw error
            }

            if (intStr.IndexOf('-') == idxFirstDigit-1) //chek for neg sign
               sum *= -1;
            
            return sum;

        }

}

public class Program
{
 
 public static void Main()
 {
  
            Stopwatch sw = new Stopwatch();
            sw.Start();
            Console.WriteLine("aaaa12451a 1".GetFirstIntFast());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString() + " ticks");
            sw.Reset();
            sw.Start();
            Console.WriteLine("aaaaa-12452a 2".GetFirstIntFast());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString() + " ticks");
            sw.Reset();
            sw.Start();
            Console.WriteLine("aaaaaa+12453a 3".GetFirstIntFast());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString() + " ticks");
            sw.Reset();
            sw.Start();
            Console.WriteLine("aaaaaa".GetFirstIntFast());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString() + " ticks");
            Console.WriteLine("1122222222222222222222".GetFirstIntFast());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString() + " ticks");
 
 }
}

Monday, June 22, 2020

How to setup font size for GNU Emacs for Windows

Luckily this is one of the easier setting to change. The Default Font for GNU Emacs for Windows, is available under Options -> Set Default Font...

Emacs GUI client for Windows is free download here.
































Choose your font family and size. And remember to save your options. 


















































Thursday, June 18, 2020

C# .Net - Fast Modulo solutions, including bit-wise and additive

Expanding on my last post, these are fast possible alternative implementations of modulo in C# .Net.

I added the simple additive modulo operation that adds a variable in a loop until it exceeds the amount. The bit-wise shifting Russian Peasant implementation of modulo is also here.
In C language, Russian Peasant does beat the native mod operand, especially the inline  assembly code version.

However, in C# you be hard pressed to beat the native implementation.
 


using System;
using System.Diagnostics; 
     
public class Program
{
 public static int ModuloBitShiftRussianPeasant(int i, int j)
    {
  if (i <= j) //trivial modulo
   return (i == j) ? 0 : i;
  else if (j==0)
   return i;

  int x = j;
  int halfi = i >> 1;
  while (x < halfi)
  {
   x <<= 1;
  }
  while (i >= j)
  {
   if (i >= x)
    i -= x;
   else
    x >>= 1;
  }
  return i;
 }
 
 public static int ModuloDecimalMath(int i, int j)
    {
  if (i <= j) //trivial modulo
   return (i == j) ? 0 : i;
  else if (j==0)
   return i;
  
  decimal decresult = i/(decimal)j; 
  //Console.WriteLine("decresult="+decresult.ToString());
  //Console.WriteLine("denominator="+(decresult - (int)decresult ).ToString()); 
  //Console.WriteLine("modulo="+((decresult - (int)decresult)*j).ToString()); 
  //modulo=3.999999999999999999999999997 issue! 
             
  //decimal modulo = (decresult - (int)decresult)*j;   
  
  return (int)(((decresult - (int)decresult)*j)+0.000000000000000000000000003M); //add correction
 }
 
 public static int ModuloMathString(int i, int j)
    {
  if (i <= j) //trivial modulo
   return (i == j) ? 0 : i;
  else if (j==0)
   return i;
  
  string decresult = (i/(decimal)j).ToString();
  int idxperiod = decresult.IndexOf('.'); 
  if (idxperiod > -1 )
  {
   string denominator = decresult.Substring(idxperiod); 
   //Console.WriteLine("denominator="+Convert.ToDecimal(denominator).ToString());     
   i = (int)(j*(Convert.ToDecimal(denominator)+0.000000000000000000000000003M)); 
  }
  else 
   i = Convert.ToInt32(decresult); 
 
  return i;
 }
 
 public static int ModuloMathAdditive(int i, int j)
    {
  if (i <= j) //trivial modulo
   return (i == j) ? 0 : i;
  else if (j==0)
   return i;
    
       int total = 0;
       int y = 0;
  
  for (int x = 0; x < i; x++)
  {
   //Console.WriteLine("y {0} > {1} ",y,  (j - 1));
   if (y > (j - 1))
   {
    total += y;
    y = 0;
       //Console.WriteLine("x={0} total={1}",y, total);
   }
   y += 1;
   
   if ((total + y) >= i) return y;  
   
  }
       
  return total;
  
 }
 
 public static void Main()
 {
  int number = 123; 
  int div = 7; 
  int mod = 0; 
  Stopwatch sw = new Stopwatch(); 
  sw.Start(); 
  mod = number % div; 
  sw.Stop();
  
  Console.WriteLine("{0} % {1} mod={2}",number,div,mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
  sw.Reset();
  sw.Start(); 
  mod = ModuloBitShiftRussianPeasant(number, div); 
  sw.Stop();
  
  Console.WriteLine("ModuloBitShiftRussianPeasant mod="+mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
  
  sw.Reset();
  sw.Start(); 
  mod = ModuloDecimalMath(number, div); 
  sw.Stop();
  
  Console.WriteLine("ModuloDecimalMath mod="+mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
  sw.Reset();
  sw.Start(); 
  mod = ModuloMathString(number, div); 
  sw.Stop();
  
  Console.WriteLine("ModuloMathString mod="+mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
  sw.Reset();
  sw.Start(); 
  mod = ModuloMathAdditive(number, div); 
  sw.Stop();
  
  Console.WriteLine("ModuloMathAddative mod="+mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
  
  
 }
}

Wednesday, June 17, 2020

CSharp - Speed comparison of Modulo implementations including Russian Peasant

If for some odd reason you need to replace the built-in modulo operator, here are a few implementations with speed timings.  

Of particular interest the bit-wise shifting Russian Peasant implementation of modulo.
In C language, Russian Peasant does beat the native mod operand, especially the inline assembly code version.


Update: In my next post I added another implementation called simple additive method.

However, in C# you be hard pressed to beat the native implementation.



using System;
using System.Diagnostics; 
     
public class Program
{
 public static int ModuloBitShiftRussianPeasant(int i, int j)
    {
  if (i <= j) //trivial modulo
   return (i == j) ? 0 : i;
  else if (j==0)
   return i;

  int x = j;
  int halfi = i >> 1;
  while (x < halfi)
  {
   x <<= 1;
  }
  while (i >= j)
  {
   if (i >= x)
    i -= x;
   else
    x >>= 1;
  }
  return i;
 }
 
 public static int ModuloDecimalMath(int i, int j)
    {
  if (i <= j) //trivial modulo
   return (i == j) ? 0 : i;
  else if (j==0)
   return i;
  
  decimal decresult = i/(decimal)j; 
  //Console.WriteLine("decresult="+decresult.ToString());
  //Console.WriteLine("denominator="+(decresult - (int)decresult ).ToString()); 
  //Console.WriteLine("modulo="+((decresult - (int)decresult)*j).ToString()); 
  //modulo=3.999999999999999999999999997 issue! 
             
  //decimal modulo = (decresult - (int)decresult)*j;   
  
  return (int)(((decresult - (int)decresult)*j)+0.000000000000000000000000003M); //add correction
 }
 
 public static int ModuloMathString(int i, int j)
    {
  if (i <= j) //trivial modulo
   return (i == j) ? 0 : i;
  else if (j==0)
   return i;
  
  string decresult = (i/(decimal)j).ToString();
  int idxperiod = decresult.IndexOf('.'); 
  if (idxperiod > -1 )
  {
   string denominator = decresult.Substring(idxperiod); 
   //Console.WriteLine("denominator="+Convert.ToDecimal(denominator).ToString());     
   i = (int)(j*(Convert.ToDecimal(denominator)+0.000000000000000000000000003M)); 
  }
  else 
   i = Convert.ToInt32(decresult); 
 
  return i;
 }
 
 
 
 public static void Main()
 {
  int number = 123; 
  int div = 7; 
  int mod = 0; 
  Stopwatch sw = new Stopwatch(); 
  sw.Start(); 
  mod = number % div; 
  sw.Stop();
  
  Console.WriteLine("{0} % {1} mod={2}",number,div,mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
  sw.Reset();
  sw.Start(); 
  mod = ModuloBitShiftRussianPeasant(number, div); 
  sw.Stop();
  
  Console.WriteLine("ModuloBitShiftRussianPeasant mod="+mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
  
  sw.Reset();
  sw.Start(); 
  mod = ModuloDecimalMath(number, div); 
  sw.Stop();
  
  Console.WriteLine("ModuloDecimalMath mod="+mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
  sw.Reset();
  sw.Start(); 
  mod = ModuloMathString(number, div); 
  sw.Stop();
  
  Console.WriteLine("ModuloMathString mod="+mod);
  Console.WriteLine(sw.ElapsedTicks+" ticks");
  
 }
}

Monday, June 15, 2020

OneDrive 2020 Direct File Download URL Generator




Cut and past your OneDrive share URL and generate the correct download URL. 

Microsoft OneDrive Direct File Download URL Generator




<iframe src="https://onedrive.live.com/embed?cid=8F99649728BEB2F3&resid=8F99649728BEB2F3%211010&authkey=AFo8ZQ_-qj84DEQ" width="98" height="120" frameborder="0" scrolling="no"></iframe>  see instructions below, if you don't know how. NOTE : For images there an extra step below.



https://onedrive.live.com/embed?cid=8F99649728BEB2F3&resid=8F99649728BEB2F3%211010&authkey=AFo8ZQ_-qj84DEQ and populate the text-box below. To proceed click "Get Download Link" button.



4. Now, Click on Get Download Link button.


Text-box will be highlighted so you can copy the full link. To copy, right-click and choose  "Copy" or simply (ctrl-c) to copy link. Note: Entire URL is automatic selected for your convenience.





 


For Images, you get a direct url
  1. Right-click on image and select Embed. The Copy the URL to embed image now gives you direct download URL, but is super long.

    So you do not need to do the above! 


Wednesday, June 10, 2020

CSharp - Fastest way of getting IPv4 Subnet Mask expansion aka CIDR IP, and speed comparisons

Here's a couple of implementation of getting IPv4 subnet mask exapansion or more specifically a CIDR IP subnet mask expansion.

CIDR notation is a compact representation of an IP address and its associated routing prefix. The notation is constructed from an IP address, a slash ('/') character, and a decimal number. The trailing number is the count of leading 1 bits in the routing mask, traditionally called the network mask. The IP address in the notation is always represented according to the standards for IPv4 or IPv6.

192.168.100.14/24 represents the IPv4 address 192.168.100.14 and its associated routing prefix 192.168.100.0, or equivalently, its subnet mask 255.255.255.0, which has 24 leading 1-bits.

https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing 




Code


using System;
using System.Diagnostics;
//https://docs.microsoft.com/en-us/archive/blogs/knom/ip-address-calculations-with-c-subnetmasks-networks
public static class SubnetMask
{
 public static readonly System.Net.IPAddress ClassA = System.Net.IPAddress.Parse("255.0.0.0");
 public static readonly System.Net.IPAddress ClassB = System.Net.IPAddress.Parse("255.255.0.0");
 public static readonly System.Net.IPAddress ClassC = System.Net.IPAddress.Parse("255.255.255.0");

 public static System.Net.IPAddress CreateByHostBitLength(int hostpartLength)
 {
  int hostPartLength = hostpartLength;
  int netPartLength = 32 - hostPartLength;

  if (netPartLength < 2)
   throw new ArgumentException("Number of hosts is to large for IPv4");

  Byte[] binaryMask = new byte[4];

  for (int i = 0; i < 4; i++)
  {
   if (i * 8 + 8 <= netPartLength)
    binaryMask[i] = (byte)255;
   else if (i * 8 > netPartLength)
    binaryMask[i] = (byte)0;
   else
   {
    int oneLength = netPartLength - i * 8;
    string binaryDigit =
     String.Empty.PadLeft(oneLength, '1').PadRight(8, '0');
    binaryMask[i] = Convert.ToByte(binaryDigit, 2);
   }
  }
  return new System.Net.IPAddress(binaryMask);
 }

 public static System.Net.IPAddress CreateByNetBitLength(int netpartLength)
 {
  int hostPartLength = 32 - netpartLength;
  return CreateByHostBitLength(hostPartLength);
 }

 public static System.Net.IPAddress CreateByHostNumber(int numberOfHosts)
 {
  int maxNumber = numberOfHosts + 1;

  string b = Convert.ToString(maxNumber, 2);

  return CreateByHostBitLength(b.Length);
 }
}
public static class Extensions
{
    /// <summary>
    /// Fastest way to to find 1st number in a string and convert it into an absolute integer
    /// </summary>
    /// <param name="intStr"></param>
    /// <returns></returns>
    //  https://metadataconsulting.blogspot.com/2020/06/CSharp-Fastest-way-to-find-a-number-or-integer-in-a-string.html
    public static int GetFirstAbsIntFast(this string intStr)
    {

        int sum = int.MinValue; //any error val -9999
        char[] n = intStr.ToCharArray(); //fastest way to index a string
        //int idxFirstDigit = -1;

        for (int i = 0; i < n.Length; i++)
        {
            if (n[i] >= 48 && n[i] <= 57)  //'0'=48 and '9'=57 get lead number only
            {
                //if (idxFirstDigit == -1) idxFirstDigit = i;
                int z = sum * 10 + (n[i] - 48);
                if (z < 0) //we get into negative, if over int.MaxValue
                    return sum; //we have negative number, it's an error or throw error
                sum = z;
            }
            else //if (idxFirstDigit > -1)
                break;
            //return int.MinValue; //or throw error
        }

        //if (intStr.IndexOf('-') == idxFirstDigit - 1) //chek for neg sign
        //    sum *= -1;

        return sum;

    }
 
 public static string GetIPv4NetworkMaskByPrefix(this string subnet)
    {
        //CIDR IP format accepted  xxx.xxx.xxx.xxx/1-32
        int idxForwardSlash = subnet.IndexOf('/');
        if (string.IsNullOrEmpty(subnet) && idxForwardSlash > -1)
            return string.Empty;

        string CIDRIP = subnet.Substring(idxForwardSlash+1);

        int numCIDRIP = 0;
        numCIDRIP = CIDRIP.GetFirstAbsIntFast();
        if (numCIDRIP < 1 || numCIDRIP > 32) return string.Empty; // /1-32 range accepted for ip4

        int calSubNet = 0;
        calSubNet = numCIDRIP;

        switch (calSubNet)
        {
            case 1: return "128.0.0.0"; //2,147,483,646
            case 2: return "192.0.0.0"; //1,073,741,822
            case 3: return "224.0.0.0"; //536,870,910
            case 4: return "240.0.0.0"; //268,435,454
            case 5: return "248.0.0.0"; //134,217,726
            case 6: return "252.0.0.0"; //67,108,862
            case 7: return "254.0.0.0"; //33,554,430
            case 8: return "255.0.0.0";
            case 9: return "255.128.0.0";
            case 10: return "255.192.0.0";
            case 11: return "255.224.0.0";
            case 12: return "255.240.0.0";
            case 13: return "255.248.0.0";
            case 14: return "255.252.0.0";
            case 15: return "255.254.0.0";
            case 16: return "255.255.0.0";
            case 17: return "255.255.128.0";
            case 18: return "255.255.192.0";
            case 19: return "255.255.224.0";
            case 20: return "255.255.240.0";
            case 21: return "255.255.248.0";
            case 22: return "255.255.252.0";
            case 23: return "255.255.254.0";
            case 24: return "255.255.255.0";  //254
            case 25: return "255.255.255.128";
            case 26: return "255.255.255.192";
            case 27: return "255.255.255.224";
            case 28: return "255.255.255.240";
            case 29: return "255.255.255.248";
            case 30: return "255.255.255.252";
            case 31: return "255.255.255.254"; 
            case 32: return "255.255.255.255";
            default: return "";
        }
    }

    //https://www.ipaddressguide.com/netmask
    //A CIDR IP address looks like a normal IP address except that it ends with a slash followed by a number, called the IP network prefix.
    //10.0.0.0/24 -> Netmask = 255.255.255.0
    public static string GetIPv4SubnetMask(this string subnet)
    {
        //CIDR IP format accepts -> {xxx.xxx.xxx.xxx}/[1-32]
        int idxForwardSlash = subnet.IndexOf('/');
        if (string.IsNullOrEmpty(subnet) && idxForwardSlash > -1)
            return string.Empty;

        string CIDRIP = subnet.Substring(idxForwardSlash+1);

        int numCIDRIP = 0;
        numCIDRIP = CIDRIP.GetFirstAbsIntFast();
        if (numCIDRIP < 1 || numCIDRIP > 32) return string.Empty; // /1-32 range accepted for ip4

        int calSubNet = 0;
        calSubNet = 32 - numCIDRIP;

        // https://weblogs.asp.net/razan/finding-subnet-mask-from-ip4-address-using-c
        long mask = (0xffffffffL << calSubNet & 0xffffffffL);
        mask = System.Net.IPAddress.HostToNetworkOrder((int)mask);
        return new System.Net.IPAddress((UInt32)mask).ToString();
    }

        public static string getSubnetAddressFromIPv4NetMask(this string netMask)
        {
            //CIDR IP format accepted  xxx.xxx.xxx.xxx/1-32
            int idxForwardSlash = netMask.IndexOf('/');
            if (string.IsNullOrEmpty(netMask) && idxForwardSlash > -1)
                return string.Empty;

            string CIDRIP = netMask.Substring(idxForwardSlash + 1);

            int numCIDRIP = 0;
            numCIDRIP = CIDRIP.GetFirstAbsIntFast();
            if (numCIDRIP < 1 || numCIDRIP > 32) return string.Empty; // /1-32 range accepted for ip4

            //long bit = 1;
            //bit <<= pow; //now this bitwise shift works
            int calSubNet = 0;
            calSubNet = 32 - numCIDRIP;

            string subNetMask = string.Empty;

            double result = 0;

            if (calSubNet >= 0 && calSubNet <= 8)
            {
                for (int ipower = 0; ipower < calSubNet; ipower++)
                {
                    long bit = 1;
                    bit <<= ipower; //now this bitwise shift works
                    result += bit; 
                    //result += Math.Pow(2, ipower);
                }
                double finalSubnet = 255 - result;
                subNetMask = "255.255.255." + Convert.ToString(finalSubnet);
            }
            else if (calSubNet > 8 && calSubNet <= 16)
            {
                int secOctet = 16 - calSubNet;

                secOctet = 8 - secOctet;

                for (int ipower = 0; ipower < secOctet; ipower++)
                {
                    long bit = 1;
                    bit <<= ipower; //now this bitwise shift works
                    result += bit;
                    //result += Math.Pow(2, ipower);
                }
                double finalSubnet = 255 - result;
                subNetMask = "255.255." + Convert.ToString(finalSubnet) + ".0";
            }
            else if (calSubNet > 16 && calSubNet <= 24)
            {
                int thirdOctet = 24 - calSubNet;

                thirdOctet = 8 - thirdOctet;

                for (int ipower = 0; ipower < thirdOctet; ipower++)
                {
                    long bit = 1;
                    bit <<= ipower; //now this bitwise shift works
                    result += bit;
                    //result += Math.Pow(2, ipower);
                }
                double finalSubnet = 255 - result;
                subNetMask = "255." + Convert.ToString(finalSubnet) + ".0.0";
            }
            else if (calSubNet > 24 && calSubNet <= 32)
            {
                int fourthOctet = 32 - calSubNet;

                fourthOctet = 8 - fourthOctet;

                for (int ipower = 0; ipower < fourthOctet; ipower++)
                {
                    long bit = 1;
                    bit <<= ipower; //now this bitwise shift works
                    result += bit;
                    //result += Math.Pow(2, ipower);
                }
                double finalSubnet = 255 - result;
                subNetMask = Convert.ToString(finalSubnet) + ".0.0.0";
            }

            return subNetMask;
        }

 public static System.Net.IPAddress CreateBySubNetBitLength(this string netMask)
 {
  //CIDR IP format accepted  xxx.xxx.xxx.xxx/1-32
  int idxForwardSlash = netMask.IndexOf('/');
  if (string.IsNullOrEmpty(netMask) && idxForwardSlash > -1)
   return System.Net.IPAddress.None;

  string CIDRIP = netMask.Substring(idxForwardSlash + 1);

  int numCIDRIP = 0;
  numCIDRIP = CIDRIP.GetFirstAbsIntFast();
  if (numCIDRIP < 1 || numCIDRIP > 32) return System.Net.IPAddress.None; // /1-32 range accepted for ip4

  int calSubNet = 32 - numCIDRIP;

  return SubnetMask.CreateByNetBitLength(calSubNet);

 }


}
    
public class Program
{
 
 public static void Main()
 { 
      //https://www.calculator.net/ip-subnet-calculator.html dup this functionality partially
       
      string subnetprefix = "/25"; 
   Stopwatch sw = new Stopwatch(); 
            sw.Start(); 
            Console.WriteLine("Using getSubnetAddressFromIPNetMask");
            Console.WriteLine(subnetprefix.getSubnetAddressFromIPv4NetMask());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString("#,0") + " ticks");
            sw.Reset();
            sw.Start(); 
            Console.WriteLine("Using compact GetSubnetMask");
            Console.WriteLine(subnetprefix.GetIPv4SubnetMask());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString("#,0") + " ticks");
            sw.Reset();
            sw.Start(); 
            Console.WriteLine("Using compact getNetworkMaskByPrefix");
            Console.WriteLine(subnetprefix.GetIPv4NetworkMaskByPrefix());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString("#,0") + " ticks");
            //https://docs.microsoft.com/en-us/archive/blogs/knom/ip-address-calculations-with-c-subnetmasks-networks
      Console.WriteLine("Using Microsoft's recommended imp - CreateBySubNetBitLength");
            Console.WriteLine(subnetprefix.GetIPv4NetworkMaskByPrefix());
            sw.Stop();
            Console.WriteLine(sw.ElapsedTicks.ToString("#,0") + " ticks");
  
  
 }
}