Caesar Cipher Algorithm Wrong  ??

public class caesarCipher {
      public static void main(String args[]) {
      int num1=0,donothing=0;
      char[] s1 = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
      'p','q','r','s','t','u','v','w','x','y','z'};
      System.out.println("Please enter a caesar cipher shift between 1-26 :");
      num1 = SavitchIn.readInt();
          do {
                System.out.println("ERROR: Please enter a caesar cipher shift between 1-26 :");
                num1 = SavitchIn.readInt();
          }while(num1>26 && num1<1);
          while(num1<27 && num1>0) {
                System.out.println("Please enter some plaintext to be  encoded");
                String s2 = SavitchIn.readLine();
                s2=s2.toLowerCase();
                int length1 = s2.length();
                for (int i=0; i<s2.length(); i++) {
                      for (int j=0; j<s2.length(); j++) {
                            if( s2.charAt(i)==s1[j] )
                                  System.out.print( s1[(j+num1)%26] );
                            else if ( s2.charAt(i)!=s1[j] )
                                  donothing++;
                System.out.println();
                System.exit(0);
}The program works fine if the user enters abc.. but if anything else is entered e.g fghkl the program prints a blank.
Any ideas where I went wrong on this as I am pulling my hair out trying to work it out :)
Thanks for any help
Se�n

I tried 26 instead of s1.length(), thanks for the help
as the idea was correct.No, no, no. Again, use s1.length (not s1.length()). Don't hard-code constants like "26", as then your code is more fragile if you change the actual array size.

Similar Messages

  • Caesar Cipher and non printing ascii

    I am writing a program to implements the caesar cipher. For the program I am using ASCII code so my encryption algorithm is:
    c = (p + k) mod 128
    The only problem is, is that depending on the characters being encrypted and depending on the key I use some of the characters are encrypted to non-printing ascii characters such as 'del'.
    So my code reads in the plain text from a file converts each character to ascii, encrypts each character using the key. It then writes the encrypted ascii values to a file as text (i.e. the character equivalent of the ascii).
    If I do then encounter a non-printing ascii value it is written to the file as a square shape. Is there any way I can get around this?
    Thanks for your help on the matter.
    Wallace

    Modify your encryption function so that it only covers those ASCII values that print, i.e. you need to implement the mod and + function yourself so that only good ASCII characters are considered.

  • Caesar Cipher

    I'm trying to do a basic caesar cipher shift by 1. This is my code so far but its off by one letter. Could someone tell me whats wrong with it? Thx
         public void caesarCipher()
              char[] letters = {'A','B','C','D','E','F','G','H','I','J','K',
                        'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
              for(int x=0; x<letters.length; x++)
                   int n=1;
                   letters[x]=letters[(x+n)%26];
                   System.out.print(letters[x]);
         }This is the output of this code:
    BCDEFGHIJKLMNOPQRSTUVWXYZB

    You start at the beginning of the array, modifying its contents, and at the end loop around to the beginning of the array again, after you have already modified that position.
    Don't even bother trying to encode it in-place. Create a new array for output.

  • Is any one give me a Caesar Cipher algo in Jsp

    hi frnds
    i want to give password security in my web-page so what i want i simple input simple password text and i store that password text as a Caesar Cipher encription and when i retrive that it come with descriptions example like below
    if enter
    abcd
    store in db like
    fjsd
    and when user enter
    abcd
    it dycript [fjsd] and come abcd
    means password store in db as Caesar Cipher text
    if send me then my id is [email protected]
    thnx

    The libs needed for the OS including the hearders
    may not be installed if the OS was not originally
    installed as a developer system. The libs are not
    included in the compilers if they have to be
    supported at runtime in the OS, or if they have to
    be there at link time for third party compilers,
    such as gcc. You must find the package that contains
    them on the OS distribution and install them from
    that package. Your sysadmin should be able to do
    this.

  • KeyStore Algorithm & Cipher Algorithm

    Hi,
         Generated the KeyStore using the keytool using Default KeyStrore Type & KeyStore = User, Password=password
         With keystore am able to retrieve the both Private & Public Keys by making use of KeyStore.getDefaultType())
         When i tried 2 encrypt the message using the params Cipher, PublicKey, MESSAGE, Cipher.ENCRYPT_MODE
         As above cipher is initialized with "RSA" & meantime the KeyStore is also created by "RSA"
         But when program is executed, getting an error "java.security.InvalidKeyException: Could not initialize for signing with the given key"
         Kindly inform me what must be the [-keyalg <keyalg>] used for both KeyStore & initialization of Cipher
    NOTE: am using the JDK1.4
    Cordially

    can u send me the code for the signing.
    Rgds,
    Anand

  • Ask  help  for a question about Caesar cipher

    "Caesar ciphers are among the simplest devised, and rely solely on remapping characters to others in the alphabet using a constant shift modulo the size of the alphabet. The amount shifted is the key used to encipher, or decipher, the message. This remapping is usually restricted to letters, so that with a key of 2, `A' is replaced by `C', `B' by `D', ..., `X' by `Z', `Y' by `A', and `Z' by `B'. Lower case letters are mapped in an identical way to give their lower case replacements. Thus here the key is an integer in the range 1 to 25 (not 0 to 25, as there is no point replacing every `A' by an `A' etc.).
    Straightforward Caesar ciphers are rather too easy to recognise however. In an attempt to maintain the basic idea, but complicate the result, what we will do is systemmatically jumble up the letters. Treating `I' and `J' as one letter from the start (so now there are only 24 different keys, assuming we still exclude mapping `A' to `A'), the 25 letters will be written to a 5 by 5 grid, by rows, and read back by columns. So, for example, with a key of 10, `A' is mapped into `L', and the grid produced is:
    L M N O P
    Q R S T U
    V W X Y Z
    A B C D E
    F G H I K
    and the uppercase alphabet upon encryption becomes: LQVAFMRWBBGNSXCHOTYDIPUZEK Note that here the `B' is doubled up because it represents both `I' and `J'. Thus, with this key of 10, the following line is enciphered to the one after it.
    Caesar ciphers are child's play.
    Vlfylt vbhwfty ltf vwbna'y hnle.
    An acceptable drawback of the treatment of `I' and `J' in the grid is that a decoded message will have all `J's mapped to `I's, and all `j's to `i's"
    this is a part of requirement in the whole program,I almost finished it, but I do not know thata how to make" a decoded message will have all `J's mapped to `I's, and all `j's to `i's". "Treating `I' and `J' as one letter from the start"?what does that mean?
    this is my code about the part:
    public static char encode(char ch,int n)  {
      while (!Character.isLetter(ch))
       return ch;
      if(ch>='A'&&ch<='Z')
      return (char)('A'+(ch-'A'+n)%26);
    if(ch>='a'&&ch<='z')
      return (char)('a'+(ch-'a'+n)%26);
    return ch;
    public static char decode(char ch,int n)  {
      while (!Character.isLetter(ch))
       return ch;
      if(ch>='A'&&ch<='Z')
      return (char)('A'+(ch-'A'-n)%26);
    if(ch>='a'&&ch<='z')
      return (char)('a'+(ch-'a'-n)%26);
    return ch;
    }but
    how to make" a decoded message will have all `J's mapped to `I's, and all `j's to `i's". "Treating `I' and `J' as one letter from the start"?

    Your teacher/instructor/professor would obviously be the final authority on this, but I think all it's saying is that when you encode, treat each 'j' you come across as an 'i', and therefore, when you decode, because you've lost information that it was a 'j' to start with, it will be mapped back to an 'i'.
    One easy way to accomplish this (that would save special cases later in your for-loop) would simply be a:
    String toEncode = "Djibouti"
    toEncode = toEncode.replaceAll("j","i"); //obviously handle both cases instead
    String encoded = encode(toEncode);
    String decoded = decode(encoded);
    System.out.println(decoded); //this would print "Diibouti"The other way is to simply add a special case to your encode/decode (char) methods.
    Edited by: endasil on 28-Sep-2009 9:35 AM

  • Caesar Cipher   java source code.

    PLZ, what is the wrong her??
    import java.io.*;
    import java.util.*;
    import java.util.Scanner;
    public class Substitution
      public String str;
      public String k;
       // main function
       public static void main(String[] args)
         Scanner scan = new Scanner(System.in);
        System.out.println("Enter character: ");
        String message=scan.nextLine();
         System.out.println("Enter key: ");
         String key=scan.nextLine();
         Substitution caes= new Substitution ();
         String encrypt = caes.translate(message,key);
         System.out.println("Encrypted: "+encrypt);
          String decrypt = caes.translate(encrypt,-1*key );
         System.out.println("Decrypted: "+decrypt);
      //constractor
       public Substitution( ) { }
      //function of translate for encrypt and decrypt
       public String translate (String str ,String k)
             StringBuffer str1= new StringBuffer(str);
             String s = "abcdefghijklmnopqrstuvwxyz";
             String d="thesnowlayickpdfrvbg-----";
             for (int j=0;j<str.length();j++)
              for(int t=0;t<k.length();t++)
              for(int i=0;i<26;i++)
                if(str.charAt(j)==s.charAt(i) )
                 if(d.charAt(t)==s.charAt(i))
                  str1.setCharAt(j,s.charAt((i+t+26)%26));
                  break;
               return str1.toString();
          Thank you

    -1*key?? What might that mean? This question is probably more appropriate for [this |http://forum.java.sun.com/forum.jspa?forumID=54] forum.

  • A problem about ALG_DES_CBC_ISO9797_M2 cipher

    I am doing a test for DES encryption/decryption using cref. Looks like only few cipher algorithms are support by Java card OS. I use ALG_DES_CBC_ISO9797_M2.
    The problem is as below:
    I use RMI.
    I think the operation block is 8 bytes.
    I want to encrypt an 8 bytes array 30 31 32 33 34 35 36 37.
    However, if I send an input array with 8 bytes, I got the error ILLGAL_USE.
    The strange thing is that if I append 8 bytes zeros and make the array like 30 31 32 33 34 35 36 37 00 00 00 00 00 00 00 00,
    I got a result 97 44 20 6c 39 80 c2 27 3d f6 77 5c 15 e7 84 18.
    And if I use the result array (16 bytes) for decryption, I got 30 31 32 33 34 35 36 37 00 00 00 00 00 00 00 00, which looks right,
    if I truncate last 8 bytes.
    Another experiment:
    Array1 (16 bytes): 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f (instead of append zeros, I append other numbers)
    Array2, encryption result for Array1: 9744206c3980c2273df6775c15e78418
    decrypt Array
    I got the result: 30 31 32 33 34 35 36 37 00 00 00 00 00 00 00 00 (looks like only the first 8 bytes of Array1 is used)
    So I have to keep a double-size encryption result? Anybody has more information?

    I know it's weird. But if I use 8 bytes as input, I got this for encryption:
    [java] java.lang.ArrayIndexOutOfBoundsException: Thrown on the card.
    my encryption code is like this:
    (if I double the size of outBuffer, I got an output array with size 16 bytes)
    public class DESCrypto {
         //DES Test Key
         static byte[] testDESKey = //Note this is the DES key definition
              (byte)0x38, (byte)0x12, (byte)0xA4, (byte)0x19, (byte)0xC6, (byte)0x3B, (byte)0xE7, (byte)0x71
         // constants
         byte     cryptKeyType = KeyBuilder.TYPE_DES;
         short     cryptKeyLen = KeyBuilder.LENGTH_DES;          // 64 bits
         short     cryptBlockLen = KeyBuilder.LENGTH_DES / 8;
         byte     cryptAlgo = Cipher.ALG_DES_CBC_ISO9797_M2;
        byte[] outBuffer = null;
         // input length is supposed to be half of the key length, otherwise giving arrayindexoutofboundary error
        public byte[] DESEncrypt(byte[] inBuffer) throws UserException, CryptoException {
              if(null == outBuffer) {
                   outBuffer = JCSystem.makeTransientByteArray((short)(this.cryptBlockLen), JCSystem.CLEAR_ON_DESELECT);
              if(null == outBuffer) {
                   UserException.throwIt(CardRmiCommon.NULL_POINTER);
              try {
                 Cipher cipher = Cipher.getInstance(this.cryptAlgo, false);
                 DESKey key = (DESKey) KeyBuilder.buildKey(this.cryptKeyType, this.cryptKeyLen, false);
                   key.setKey(testDESKey, (short)0);
                   cipher.init(key, Cipher.MODE_ENCRYPT);
                   cipher.doFinal(inBuffer,(short)0, (short)cryptBlockLen, outBuffer,(short)0);
              catch(CryptoException e){
                   CryptoException.throwIt(e.getReason());
              return outBuffer;
    }

  • Algorithms such as ALG_RSA_ISO9796

    How can I know what EXACTLY this algorithm does ?
    The documentation says "Cipher algorithm ALG_RSA_ISO9796 provides a cipher using RSA. Input data is padded according to the ISO 9796 (EMV'96) scheme.".
    I know EMV and RSA pretty well, what I want to know is what EXACTLY is done. In that case, I would guees that it computes a SHA hash on the message, splits i, add a header and a trailer and then sign (like in EMV).
    Where can I find :
    1) the exact definition of the ciphers (this one and others)
    2) test vectors
    Thanks in advance.

    EMV'96 not only defines the use of the RSA algorithm for digital signature. It also can be used to cipher general data.
    See annex E (for digital signature) and F (for ciphering).
    From my point of view, ALG_RSA_ISO9796 doesn't pad the data (excepts for the 0's adding) for odd exponents, but it have a different ciphering behaviour for even exponents.
    That is what this contant define.

  • NoSuchAlgorithmException : Algorithm DESede not available

    Hi,
    Could any one tell me why this error comes
    The particular method which throws the Exception is
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
    The Exception stackTrace is
    java.security.NoSuchAlgorithmException: Algorithm DESede not available
    at javax.crypto.SunJCE_b.a(DashoA6275)
    at javax.crypto.SecretKeyFactory.getInstance(DashoA6275)
    at com.orbitech.armor.syncd.server.ArmorKeyTabFile.ReadKeyTabFile(ArmorK
    eyTabFile.java:173)
    at com.orbitech.armor.syncd.server.OracleRegistryPlugin.init(OracleRegis
    tryPlugin.java:210)
    at ArmorSystemServlet.processPrnInfo(ArmorSystemServlet.java:194)
    at ArmorSystemServlet.doPost(ArmorSystemServlet.java:137)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:826)
    at com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRun
    ner.java:533)
    com.orbitech.armor.syncd.server.ArmorException: Error in Reading Keytab file
    at com.orbitech.armor.syncd.server.ArmorKeyTabFile.ReadKeyTabFile(ArmorK
    eyTabFile.java:212)
    at com.orbitech.armor.syncd.server.OracleRegistryPlugin.init(OracleRegis
    tryPlugin.java:210)
    at ArmorSystemServlet.processPrnInfo(ArmorSystemServlet.java:194)
    at ArmorSystemServlet.doPost(ArmorSystemServlet.java:137)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:826)
    at com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRun
    ner.java:533)
    Im trying to use JCE api's in a servlet running under a iplanet ssl server. Also my classpath setting contains the jce jars as well.
    I am able to see very well the SunJCE provider and the algorithm are installed. The code I used too see them is
    System.out.println("Cipher algorithms : ");
    Object[] o = Security.getAlgorithms("Cipher").toArray();
    for (int i=0; i<o.length; i++) {
    System.out.println((String) o[ i ]);
    Cipher algorithms :
    BLOWFISH
    DESEDE
    PBEWITHMD5ANDTRIPLEDES
    DES
    PBEWITHMD5ANDDES
    System.out.println("MessageDigest algorithms : ");
    o = Security.getAlgorithms("MessageDigest").toArray();
    for (int i=0; i<o.length; i++) {
    System.out.println((String) o[ i ]);
    MessageDigest algorithms :
    MD5
    SHA
    System.out.println("Signature algorithms : ");
    o = Security.getAlgorithms("Signature").toArray();
    for (int i=0; i<o.length; i++) {
    System.out.println((String) o[ i ]);
    Signature algorithms :
    MD2WITHRSA
    MD5WITHRSA
    SHA1WITHDSA
    SHA1WITHRSA
    System.out.println("Mac algorithms : ");
    o = Security.getAlgorithms("Mac").toArray();
    for (int i=0; i<o.length; i++) {
    System.out.println((String) o[ i ]);
    Mac algorithms :
    HMACSHA1
    HMACMD5
    System.out.println("Keystore algorithms : ");
    o = Security.getAlgorithms("Keystore").toArray();
    for (int i=0; i<o.length; i++) {
    System.out.println((String) o[ i ]);
    Keystore algorithms :
    PKCS12
    JCEKS
    JKS
    System.out.println("Providers : ");
    Provider p[] = Security.getProviders();
    for(int i = 0; i<p.length; i++) {
    System.out.println( p.getName());
    Providers :
    SUN
    SunJSSE
    SunRsaSign
    SunJCE
    SunJGSS
    Thanks in advance
    regds........jp

    try this...it worked for me......
    put all four JCE jar files in the ext folder buried deep inside ur program files ...I have it in >> "C:\Program Files\Java\j2re1.4.1_02\lib\ext" folder .Now edit the file "C:\Program Files\Java\j2re1.4.1_02\lib\security\java.security" and add register ur provider by adding the line>> security.provider.2=com.sun.crypto.provider.SunJCE
    save the file and rerun the program..the exception should vanish..
    Sanjit R
    US Software Pvt Ltd
    Technopark,
    Trivandrum
    Kerala
    India

  • [S]bad perf b/c (lack of fine-tuning)/(wrong governor)/(redundancy)?

    hiho,
    my hardinfo benchmark results:
    CPU Blowfish
    CPU Blowfish
    This Machine 800 MHz 7,602
    Intel(R) Celeron(R) M processor 1.50GHz (null) 26.1876862
    PowerPC 740/750 (280.00MHz) (null) 172.816713
    CPU CryptoHash
    CPU CryptoHash
    This Machine 800 MHz 174,422
    CPU Fibonacci
    CPU Fibonacci
    This Machine 800 MHz 2,989
    Intel(R) Celeron(R) M processor 1.50GHz (null) 8.1375674
    PowerPC 740/750 (280.00MHz) (null) 58.07682
    CPU N-Queens
    CPU N-Queens
    This Machine 800 MHz 8,889
    FPU FFT
    FPU FFT
    This Machine 800 MHz 3,354
    FPU Raytracing
    FPU Raytracing
    This Machine 800 MHz 5,728
    Intel(R) Celeron(R) M processor 1.50GHz (null) 40.8816714
    PowerPC 740/750 (280.00MHz) (null) 161.312647
    system:
    Processor 2x Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
    Memory 3081MB (692MB used)
    Operating System Arch Linux
    User Name sepp (Sebastian)
    Date/Time Mo 05 Dez 2011 18:39:33 CET
    Display
    Resolution 1680x1050 pixels
    OpenGL Renderer Unknown
    X11 Vendor The X.Org Foundation
    Multimedia
    Audio Adapter HDA-Intel - HDA Intel
    Input Devices
    AT Translated Set 2 keyboard
    Sleep Button
    Lid Switch
    Power Button
    Video Bus
    PC Speaker
    HP WMI hotkeys
    ST LIS3LV02DL Accelerometer
    SynPS/2 Synaptics TouchPad
    CKF7063
    HDA Digital PCBeep
    Logitech USB Receiver
    Logitech USB Receiver
    Printers
    No printers found
    SCSI Disks
    ATA TOSHIBA MK3252GS
    TSSTcorp CDDVDW TS-L633M
    Operating System
    Version
    Kernel Linux 3.1.4-1-ARCH (x86_64)
    Compiled #1 SMP PREEMPT Tue Nov 29 08:55:45 CET 2011
    C Library GNU C Library version 2.14.1 (stable)
    Default C Compiler Unknown
    Distribution Arch Linux
    Current Session
    Computer Name alnb
    User Name sepp (Sebastian)
    Home Directory /home/sepp
    Desktop Environment Unknown (Window Manager: Mutter)
    Misc
    Uptime 1 hour, 37 minutes
    Load Average 0,00, 0,00, 0,00
    Kernel Modules
    Loaded Modules
    cryptd Software async crypto daemon
    aes_x86_64 Rijndael (AES) Cipher Algorithm, asm optimized
    aes_generic Rijndael (AES) Cipher Algorithm
    ipv6 IPv6 protocol stack for Linux
    fuse Filesystem in Userspace
    microcode Microcode Update Driver
    coretemp Intel Core temperature monitor
    snd_hda_codec_analog Analog Devices HD-audio codec
    uvcvideo USB Video Class driver
    videodev Device registrar for Video4Linux drivers v2
    media Device node registration for media drivers
    v4l2_compat_ioctl32
    radeon ATI Radeon
    joydev Joystick device interfaces
    snd_hda_intel Intel HDA driver
    arc4 ARC4 Cipher Algorithm
    ttm TTM memory manager subsystem (for DRM device)
    iwlagn Intel(R) Wireless WiFi Link AGN driver for Linux
    snd_hda_codec HDA codec core
    snd_hwdep Hardware dependent layer
    snd_pcm Midlevel PCM code for ALSA.
    iTCO_wdt Intel TCO WatchDog Timer Driver
    hp_accel Glue between LIS3LV02Dx and HP ACPI BIOS and support for disk protection LED.
    lis3lv02d ST LIS3LV02Dx three-axis digital accelerometer driver
    hp_wmi HP laptop WMI hotkeys driver
    drm_kms_helper DRM KMS helper
    drm DRM shared core routines
    iTCO_vendor_support Intel TCO Vendor Specific WatchDog Timer Driver Support
    evdev Input driver event char devices
    psmouse PS/2 mouse driver
    sparse_keymap Generic support for sparse keymaps
    mac80211 IEEE 802.11 subsystem
    cfg80211 wireless configuration support
    sky2 Marvell Yukon 2 Gigabit Ethernet driver
    i2c_algo_bit I2C-Bus bit-banging algorithm
    rfkill RF switch support
    i2c_core I2C-Bus main module
    snd_timer ALSA timer interface
    snd Advanced Linux Sound Architecture driver for soundcards.
    soundcore Core sound module
    serio_raw Raw serio driver
    intel_agp
    container ACPI container driver
    intel_gtt
    pcspkr PC Speaker beeper driver
    wmi ACPI-WMI Mapping Driver
    snd_page_alloc Memory allocator for ALSA system.
    input_polldev Generic implementation of a polled input device
    video ACPI Video Driver
    fan ACPI Fan Driver
    thermal ACPI Thermal Zone Driver
    battery ACPI Battery Driver
    ac ACPI AC Adapter Driver
    button ACPI Button Driver
    cpufreq_powersave CPUfreq policy governor 'powersave'
    cpufreq_ondemand 'cpufreq_ondemand' - A dynamic cpufreq governor for Low Latency Frequency Transition capable processors
    acpi_cpufreq ACPI Processor P-States Driver
    freq_table CPUfreq frequency table helpers
    processor ACPI Processor Driver
    mperf
    usbhid USB HID core driver
    hid
    vfat VFAT filesystem support
    fat
    ext4 Fourth Extended Filesystem
    jbd2
    crc16 CRC16 calculations
    ext2 Second Extended Filesystem
    mbcache Meta block cache (for extended attributes)
    uhci_hcd USB Universal Host Controller Interface driver
    ehci_hcd USB 2.0 'Enhanced' Host Controller (EHCI) Driver
    usbcore
    sr_mod SCSI cdrom (sr) driver
    cdrom
    sd_mod SCSI disk (sd) driver
    ahci AHCI SATA low-level driver
    libahci Common AHCI SATA low-level routines
    libata Library module for ATA devices
    scsi_mod SCSI core
    Boots
    Boots
    Mon Dec 5 1177:0 33..1.4-1-ARCH|-
    Mon Dec 5 1144:4 33..1.4-1-ARCH|-
    Sun Dec 4 1199:2 33..1.4-1-ARCH|-
    Sun Dec 4 1199:2 33..1.4-1-ARCH|-
    Sun Dec 4 1177:4 33..1.4-1-ARCH|-
    Sun Dec 4 1144:1 33..1.4-1-ARCH|-
    Sun Dec 4 1144:0 33..1.4-1-ARCH|-
    Sun Dec 4 1133:4 33..1.4-1-ARCH|-
    Sat Dec 3 1122:3 33..1.4-1-ARCH|-
    Languages
    Available Languages
    de_DE German locale for Germany
    de_DE@euro German locale for Germany with Euro
    de_DE.iso88591 German locale for Germany
    de_DE.iso885915 German locale for Germany with Euro
    de_DE.utf8 German locale for Germany
    deutsch German locale for Germany
    en_US English locale for the USA
    en_US.iso88591 English locale for the USA
    en_US.utf8 English locale for the USA
    Filesystems
    Mounted File Systems
    udev /dev 0,00 % (10,0 MiB of 10,0 MiB)
    /run /run 2,70 % (9,7 MiB of 10,0 MiB)
    /dev/sda3 / 29,00 % (16,3 GiB of 22,9 GiB)
    shm /dev/shm 0,04 % (1,5 GiB of 1,5 GiB)
    tmpfs /tmp 0,00 % (1,5 GiB of 1,5 GiB)
    /dev/sda4 /home 5,69 % (251,6 GiB of 266,7 GiB)
    /dev/sda1 /boot 25,22 % (68,1 MiB of 91,0 MiB)
    Display
    Display
    Resolution 1680x1050 pixels
    Vendor The X.Org Foundation
    Version 1.11.2
    Monitors
    Monitor 0 1680x1050 pixels
    rc.conf:
    MODULES=(acpi-cpufreq cpufreq_ondemand cpufreq_powersave)
    DAEMONS=(!hwclock syslog-ng @network @netfs @crond @dbus gdm @cpufreq @acpid laptop-mode @sensors @microcode)
    its strange that the cpu has only 800MHz during the bench.
    my ondemand threshold: 95
    does the bench cause less then 95%?
    Last edited by b0b2 (2011-12-07 14:17:41)

    sonoran wrote:
    While I ran the benchmarks gkrellm showed my cores running at 3200MHz,
    yet the hardinfo results never reported higher than 2500MHz.
    This on a 3x AMD AthlonII X3 450, modules powernow_k8 and cpufreq_ondemand.
    Stepping is 800-2000-2500-3200. Threshold is the default 95%.
    I don't think hardinfo is reporting cpu frequency correctly.
    Aha. Check out this bug from the hardinfo site:
    http://bugs.hardinfo.org/showreport.php?bugid=48
    This is a known bug. If you're using cpufreq with the ondemand governor, then the tests will be performed at 3GHz on your machine, as they're quite CPU intensive and the governor will automatically pump out more juice to the CPU.
    However, HardInfo only measures the CPU speed once, and that's the speed it displays on the benchmark window.
    Oh thank you for the answer, good Sir!
    Can you answer the 3rd question?: do you really need laptopmodetools, acpi, cpufreq & acpid? or could i deinst one of them?

  • Need help with the query to write Cipher?

    Hi, 
    I was assigned a task to write a query to encrypt and decrypt some Cipher.  I have figured out to write the procedure to encrypt and decrypt ceasar cipher. I would really appericate if you guys could help me out with this.
    .Caesar Cipher
    2.Monoalphabetic Cipher
    3.Playfair Cipher
    4.Vigenère Cipher
    5.Transposition Ciphers
    6.Rail Fence cipher
    7.Row Transposition Cipher

    Hi , 
    I sorry about just giving the names to when i resarched i saw Rail Fnce Cipher and Ceasar Cipher are the most easier ones.
    This is how rail fence cipher works .
    Codes and Ciphers :: Rail Fence
    In the rail fence cipher, the plaintext is written downwards on successive "rails" of an imaginary fence, starting a new column when the bottom is reached. The message is then read off in rows. For
    example, if we have 3 rails and a message of "This is a secret message", you would write out:
    T S A C T S G
    H I S R M S E
    I S E E E A J
    The last J is just a random letter to fill in the space. The secret message is then condensed and regrouped.
    TSACT SGHIS RMSEI SEEEA JGURL
    To decipher a message you must know the number of rails that were used to encipher it. You then break up the letters into equal groups for each rail. For example, if you are using 3 rails, you
    would break the secret message into 3 equal groups. Now you stack the groups on top of each other and read off the message vertically. If you get gibberish, then there are probably some extra letters tacked on the end of the message that are throwing off the
    grouping. Try removing one letter from the end and try again.
    So if the number of rails =3
    Plaintext :- "This is a sccerect message"
    Cipher Text:-"TSACTSGHISRMEISEEEAJ"
    Can we figure out to write a procedure or function for this.
    Rail Fence Encoder / Decoder
    Number of rails: <input class="form_txt_gr" maxlength="2" name="rails" size="3" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;border:1px solid rgb(0, 0, 0);padding:2px 1px;margin:0px 5px 0px 2px;background-color:#ffffdd;"
    type="text" value="3" />
    Plaintext
    <textarea class="form_txt_gr" cols="40" name="message" rows="5" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;border-color:#000000;padding-right:1px;padding-margin:0px 5px 0px 2px;background-color:#ffffdd;"></textarea>
    Ciphertext
    <textarea class="form_txt_gr" cols="40" name="encoded" rows="5" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;border-color:#000000;padding-right:1px;padding-margin:0px 5px 0px 2px;background-color:#ffffdd;"></textarea>
    <input class="form_submit_gr" name="encipher" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;color:#000000;border:1px solid rgb(0, 0, 0);font-weight:bold;padding-right:1px;padding-margin:0px;background-color:#ffcc66;" type="submit"
    value="Encipher" /> <input class="form_submit_gr" name="decipher" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;color:#000000;border:1px solid rgb(0, 0, 0);font-weight:bold;padding-right:1px;padding-margin:0px;background-color:#ffcc66;"
    type="submit" value="Decipher" />
    Rail Fence Encoder / Decoder
    Number of rails: <input class="form_txt_gr" maxlength="2" name="rails" size="3" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;border:1px solid rgb(0, 0, 0);padding:2px 1px;margin:0px 5px 0px 2px;background-color:#ffffdd;"
    type="text" value="3" />
    Plaintext
    <textarea class="form_txt_gr" cols="40" name="message" rows="5" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;border-color:#000000;padding-right:1px;padding-margin:0px 5px 0px 2px;background-color:#ffffdd;"></textarea>
    Ciphertext
    <textarea class="form_txt_gr" cols="40" name="encoded" rows="5" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;border-color:#000000;padding-right:1px;padding-margin:0px 5px 0px 2px;background-color:#ffffdd;"></textarea>
    <input class="form_submit_gr" name="encipher" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;color:#000000;border:1px solid rgb(0, 0, 0);font-weight:bold;padding-right:1px;padding-margin:0px;background-color:#ffcc66;" type="submit"
    value="Encipher" /> <input class="form_submit_gr" name="decipher" style="font-family:verdana, arial, sans-serif;font-size:10px;vertical-align:middle;color:#000000;border:1px solid rgb(0, 0, 0);font-weight:bold;padding-right:1px;padding-margin:0px;background-color:#ffcc66;"
    type="submit" value="Decipher" />

  • How can I get a list of BSSIDs without using netsh?

    I'm looking for an object that would have contents similar to the output of
    netsh wlan show networks mode=bssid
    I don't want to use unreliable parsing of text output, so using netsh is out.  The WMI interface that worked in windows xp doesn't work now.  There's an API, but there is no NET interface so it's pretty difficult to work with in powershell. 
    I know of a couple of adapters, but I'd like to keep this contained in one script.  I don't think I could find or write a type for the API that I could invoke in powershell.
    Is there anything else I'm missing?

    Oh, sorry, you have said that you don't want to use netsh.
    I will involve someone familiar with this to further look at this issue. Hope there is a way for you to use without the usage of netsh.
    There might be some time delay. Appreciate your patience.
    Thank you for your understanding and support.
    Regards,
    Yan Li
    Cataleya Li
    TechNet Community Support
    Thanks, but I think I got it all figured out.  I used the C# code from the managed wifi api project (http://managedwifi.codeplex.com/) though it needed a little tweaking - had to get everything in one
    namespace so powershell could easily consume it without external files.  Had to do a little manual type conversion with the output because yay unmanaged and untyped API output.  This still needs some tweaking to present it better, but this will do
    the basics.
    Note that this is two parts.  String all the code from this post and the next into one ps1.
    $NativeWifiCode = @'
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    using System.Net.NetworkInformation;
    using System.Threading;
    using System.Text;
    using System.Diagnostics;
    namespace NativeWifi
    /// <summary>
    /// Represents a client to the Zeroconf (Native Wifi) service.
    /// </summary>
    /// <remarks>
    /// This class is the entrypoint to Native Wifi management. To manage WiFi settings, create an instance
    /// of this class.
    /// </remarks>
    public static class Wlan
    #region P/Invoke API
    /// <summary>
    /// Defines various opcodes used to set and query parameters for an interface.
    /// </summary>
    /// <remarks>
    /// Corresponds to the native <c>WLAN_INTF_OPCODE</c> type.
    /// </remarks>
    public enum WlanIntfOpcode
    /// <summary>
    /// Opcode used to set or query whether auto config is enabled.
    /// </summary>
    AutoconfEnabled = 1,
    /// <summary>
    /// Opcode used to set or query whether background scan is enabled.
    /// </summary>
    BackgroundScanEnabled,
    /// <summary>
    /// Opcode used to set or query the media streaming mode of the driver.
    /// </summary>
    MediaStreamingMode,
    /// <summary>
    /// Opcode used to set or query the radio state.
    /// </summary>
    RadioState,
    /// <summary>
    /// Opcode used to set or query the BSS type of the interface.
    /// </summary>
    BssType,
    /// <summary>
    /// Opcode used to query the state of the interface.
    /// </summary>
    InterfaceState,
    /// <summary>
    /// Opcode used to query information about the current connection of the interface.
    /// </summary>
    CurrentConnection,
    /// <summary>
    /// Opcose used to query the current channel on which the wireless interface is operating.
    /// </summary>
    ChannelNumber,
    /// <summary>
    /// Opcode used to query the supported auth/cipher pairs for infrastructure mode.
    /// </summary>
    SupportedInfrastructureAuthCipherPairs,
    /// <summary>
    /// Opcode used to query the supported auth/cipher pairs for ad hoc mode.
    /// </summary>
    SupportedAdhocAuthCipherPairs,
    /// <summary>
    /// Opcode used to query the list of supported country or region strings.
    /// </summary>
    SupportedCountryOrRegionStringList,
    /// <summary>
    /// Opcode used to set or query the current operation mode of the wireless interface.
    /// </summary>
    CurrentOperationMode,
    /// <summary>
    /// Opcode used to query driver statistics.
    /// </summary>
    Statistics = 0x10000101,
    /// <summary>
    /// Opcode used to query the received signal strength.
    /// </summary>
    RSSI,
    SecurityStart = 0x20010000,
    SecurityEnd = 0x2fffffff,
    IhvStart = 0x30000000,
    IhvEnd = 0x3fffffff
    /// <summary>
    /// Specifies the origin of automatic configuration (auto config) settings.
    /// </summary>
    /// <remarks>
    /// Corresponds to the native <c>WLAN_OPCODE_VALUE_TYPE</c> type.
    /// </remarks>
    public enum WlanOpcodeValueType
    /// <summary>
    /// The auto config settings were queried, but the origin of the settings was not determined.
    /// </summary>
    QueryOnly = 0,
    /// <summary>
    /// The auto config settings were set by group policy.
    /// </summary>
    SetByGroupPolicy = 1,
    /// <summary>
    /// The auto config settings were set by the user.
    /// </summary>
    SetByUser = 2,
    /// <summary>
    /// The auto config settings are invalid.
    /// </summary>
    Invalid = 3
    public const uint WLAN_CLIENT_VERSION_XP_SP2 = 1;
    public const uint WLAN_CLIENT_VERSION_LONGHORN = 2;
    [DllImport("wlanapi.dll")]
    public static extern int WlanOpenHandle(
    [In] UInt32 clientVersion,
    [In, Out] IntPtr pReserved,
    [Out] out UInt32 negotiatedVersion,
    [Out] out IntPtr clientHandle);
    [DllImport("wlanapi.dll")]
    public static extern int WlanCloseHandle(
    [In] IntPtr clientHandle,
    [In, Out] IntPtr pReserved);
    [DllImport("wlanapi.dll")]
    public static extern int WlanEnumInterfaces(
    [In] IntPtr clientHandle,
    [In, Out] IntPtr pReserved,
    [Out] out IntPtr ppInterfaceList);
    [DllImport("wlanapi.dll")]
    public static extern int WlanQueryInterface(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In] WlanIntfOpcode opCode,
    [In, Out] IntPtr pReserved,
    [Out] out int dataSize,
    [Out] out IntPtr ppData,
    [Out] out WlanOpcodeValueType wlanOpcodeValueType);
    [DllImport("wlanapi.dll")]
    public static extern int WlanSetInterface(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In] WlanIntfOpcode opCode,
    [In] uint dataSize,
    [In] IntPtr pData,
    [In, Out] IntPtr pReserved);
    /// <param name="pDot11Ssid">Not supported on Windows XP SP2: must be a <c>null</c> reference.</param>
    /// <param name="pIeData">Not supported on Windows XP SP2: must be a <c>null</c> reference.</param>
    [DllImport("wlanapi.dll")]
    public static extern int WlanScan(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In] IntPtr pDot11Ssid,
    [In] IntPtr pIeData,
    [In, Out] IntPtr pReserved);
    /// <summary>
    /// Defines flags passed to <see cref="WlanGetAvailableNetworkList"/>.
    /// </summary>
    [Flags]
    public enum WlanGetAvailableNetworkFlags
    /// <summary>
    /// Include all ad-hoc network profiles in the available network list, including profiles that are not visible.
    /// </summary>
    IncludeAllAdhocProfiles = 0x00000001,
    /// <summary>
    /// Include all hidden network profiles in the available network list, including profiles that are not visible.
    /// </summary>
    IncludeAllManualHiddenProfiles = 0x00000002
    /// <summary>
    /// The header of an array of information about available networks.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    internal struct WlanAvailableNetworkListHeader
    /// <summary>
    /// Contains the number of <see cref="WlanAvailableNetwork"/> items following the header.
    /// </summary>
    public uint numberOfItems;
    /// <summary>
    /// The index of the current item. The index of the first item is 0.
    /// </summary>
    public uint index;
    /// <summary>
    /// Defines the flags which specify characteristics of an available network.
    /// </summary>
    [Flags]
    public enum WlanAvailableNetworkFlags
    /// <summary>
    /// This network is currently connected.
    /// </summary>
    Connected = 0x00000001,
    /// <summary>
    /// There is a profile for this network.
    /// </summary>
    HasProfile = 0x00000002
    /// <summary>
    /// Contains information about an available wireless network.
    /// </summary>
    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
    public struct WlanAvailableNetwork
    /// <summary>
    /// Contains the profile name associated with the network.
    /// If the network doesn't have a profile, this member will be empty.
    /// If multiple profiles are associated with the network, there will be multiple entries with the same SSID in the visible network list. Profile names are case-sensitive.
    /// </summary>
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
    public string profileName;
    /// <summary>
    /// Contains the SSID of the visible wireless network.
    /// </summary>
    public Dot11Ssid dot11Ssid;
    /// <summary>
    /// Specifies whether the network is an infrastructure or an ad-hoc one.
    /// </summary>
    public Dot11BssType dot11BssType;
    /// <summary>
    /// Indicates the number of BSSIDs in the network.
    /// </summary>
    public uint numberOfBssids;
    /// <summary>
    /// Indicates whether the network is connectable.
    /// </summary>
    public bool networkConnectable;
    /// <summary>
    /// Indicates why a network cannot be connected to. This member is only valid when <see cref="networkConnectable"/> is <c>false</c>.
    /// </summary>
    public WlanReasonCode wlanNotConnectableReason;
    /// <summary>
    /// The number of PHY types supported on available networks.
    /// The maximum value of this field is 8. If more than 8 PHY types are supported, <see cref="morePhyTypes"/> must be set to <c>true</c>.
    /// </summary>
    private uint numberOfPhyTypes;
    /// <summary>
    /// Contains an array of <see cref="Dot11PhyType"/> values that represent the PHY types supported by the available networks.
    /// When <see cref="numberOfPhyTypes"/> is greater than 8, this array contains only the first 8 PHY types.
    /// </summary>
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
    private Dot11PhyType[] dot11PhyTypes;
    /// <summary>
    /// Gets the <see cref="Dot11PhyType"/> values that represent the PHY types supported by the available networks.
    /// </summary>
    public Dot11PhyType[] Dot11PhyTypes
    get
    Dot11PhyType[] ret = new Dot11PhyType[numberOfPhyTypes];
    Array.Copy(dot11PhyTypes, ret, numberOfPhyTypes);
    return ret;
    /// <summary>
    /// Specifies if there are more than 8 PHY types supported.
    /// When this member is set to <c>true</c>, an application must call <see cref="WlanClient.WlanInterface.GetNetworkBssList"/> to get the complete list of PHY types.
    /// <see cref="WlanBssEntry.phyId"/> contains the PHY type for an entry.
    /// </summary>
    public bool morePhyTypes;
    /// <summary>
    /// A percentage value that represents the signal quality of the network.
    /// This field contains a value between 0 and 100.
    /// A value of 0 implies an actual RSSI signal strength of -100 dbm.
    /// A value of 100 implies an actual RSSI signal strength of -50 dbm.
    /// You can calculate the RSSI signal strength value for values between 1 and 99 using linear interpolation.
    /// </summary>
    public uint wlanSignalQuality;
    /// <summary>
    /// Indicates whether security is enabled on the network.
    /// </summary>
    public bool securityEnabled;
    /// <summary>
    /// Indicates the default authentication algorithm used to join this network for the first time.
    /// </summary>
    public Dot11AuthAlgorithm dot11DefaultAuthAlgorithm;
    /// <summary>
    /// Indicates the default cipher algorithm to be used when joining this network.
    /// </summary>
    public Dot11CipherAlgorithm dot11DefaultCipherAlgorithm;
    /// <summary>
    /// Contains various flags specifying characteristics of the available network.
    /// </summary>
    public WlanAvailableNetworkFlags flags;
    /// <summary>
    /// Reserved for future use. Must be set to NULL.
    /// </summary>
    uint reserved;
    [DllImport("wlanapi.dll")]
    public static extern int WlanGetAvailableNetworkList(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In] WlanGetAvailableNetworkFlags flags,
    [In, Out] IntPtr reservedPtr,
    [Out] out IntPtr availableNetworkListPtr);
    [Flags]
    public enum WlanProfileFlags
    /// <remarks>
    /// The only option available on Windows XP SP2.
    /// </remarks>
    AllUser = 0,
    GroupPolicy = 1,
    User = 2
    [DllImport("wlanapi.dll")]
    public static extern int WlanSetProfile(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In] WlanProfileFlags flags,
    [In, MarshalAs(UnmanagedType.LPWStr)] string profileXml,
    [In, Optional, MarshalAs(UnmanagedType.LPWStr)] string allUserProfileSecurity,
    [In] bool overwrite,
    [In] IntPtr pReserved,
    [Out] out WlanReasonCode reasonCode);
    /// <summary>
    /// Defines the access mask of an all-user profile.
    /// </summary>
    [Flags]
    public enum WlanAccess
    /// <summary>
    /// The user can view profile permissions.
    /// </summary>
    ReadAccess = 0x00020000 | 0x0001,
    /// <summary>
    /// The user has read access, and the user can also connect to and disconnect from a network using the profile.
    /// </summary>
    ExecuteAccess = ReadAccess | 0x0020,
    /// <summary>
    /// The user has execute access and the user can also modify and delete permissions associated with a profile.
    /// </summary>
    WriteAccess = ReadAccess | ExecuteAccess | 0x0002 | 0x00010000 | 0x00040000
    /// <param name="flags">Not supported on Windows XP SP2: must be a <c>null</c> reference.</param>
    [DllImport("wlanapi.dll")]
    public static extern int WlanGetProfile(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In, MarshalAs(UnmanagedType.LPWStr)] string profileName,
    [In] IntPtr pReserved,
    [Out] out IntPtr profileXml,
    [Out, Optional] out WlanProfileFlags flags,
    [Out, Optional] out WlanAccess grantedAccess);
    [DllImport("wlanapi.dll")]
    public static extern int WlanGetProfileList(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In] IntPtr pReserved,
    [Out] out IntPtr profileList
    [DllImport("wlanapi.dll")]
    public static extern void WlanFreeMemory(IntPtr pMemory);
    [DllImport("wlanapi.dll")]
    public static extern int WlanReasonCodeToString(
    [In] WlanReasonCode reasonCode,
    [In] int bufferSize,
    [In, Out] StringBuilder stringBuffer,
    IntPtr pReserved
    /// <summary>
    /// Defines the mask which specifies where a notification comes from.
    /// </summary>
    [Flags]
    public enum WlanNotificationSource
    None = 0,
    /// <summary>
    /// All notifications, including those generated by the 802.1X module.
    /// </summary>
    All = 0X0000FFFF,
    /// <summary>
    /// Notifications generated by the auto configuration module.
    /// </summary>
    ACM = 0X00000008,
    /// <summary>
    /// Notifications generated by MSM.
    /// </summary>
    MSM = 0X00000010,
    /// <summary>
    /// Notifications generated by the security module.
    /// </summary>
    Security = 0X00000020,
    /// <summary>
    /// Notifications generated by independent hardware vendors (IHV).
    /// </summary>
    IHV = 0X00000040
    /// <summary>
    /// Defines the types of ACM (<see cref="WlanNotificationSource.ACM"/>) notifications.
    /// </summary>
    /// <remarks>
    /// The enumeration identifiers correspond to the native <c>wlan_notification_acm_</c> identifiers.
    /// On Windows XP SP2, only the <c>ConnectionComplete</c> and <c>Disconnected</c> notifications are available.
    /// </remarks>
    public enum WlanNotificationCodeAcm
    AutoconfEnabled = 1,
    AutoconfDisabled,
    BackgroundScanEnabled,
    BackgroundScanDisabled,
    BssTypeChange,
    PowerSettingChange,
    ScanComplete,
    ScanFail,
    ConnectionStart,
    ConnectionComplete,
    ConnectionAttemptFail,
    FilterListChange,
    InterfaceArrival,
    InterfaceRemoval,
    ProfileChange,
    ProfileNameChange,
    ProfilesExhausted,
    NetworkNotAvailable,
    NetworkAvailable,
    Disconnecting,
    Disconnected,
    AdhocNetworkStateChange
    /// <summary>
    /// Defines the types of an MSM (<see cref="WlanNotificationSource.MSM"/>) notifications.
    /// </summary>
    /// <remarks>
    /// The enumeration identifiers correspond to the native <c>wlan_notification_msm_</c> identifiers.
    /// </remarks>
    public enum WlanNotificationCodeMsm
    Associating = 1,
    Associated,
    Authenticating,
    Connected,
    RoamingStart,
    RoamingEnd,
    RadioStateChange,
    SignalQualityChange,
    Disassociating,
    Disconnected,
    PeerJoin,
    PeerLeave,
    AdapterRemoval,
    AdapterOperationModeChange
    /// <summary>
    /// Contains information provided when registering for WLAN notifications.
    /// </summary>
    /// <remarks>
    /// Corresponds to the native <c>WLAN_NOTIFICATION_DATA</c> type.
    /// </remarks>
    [StructLayout(LayoutKind.Sequential)]
    public struct WlanNotificationData
    /// <summary>
    /// Specifies where the notification comes from.
    /// </summary>
    /// <remarks>
    /// On Windows XP SP2, this field must be set to <see cref="WlanNotificationSource.None"/>, <see cref="WlanNotificationSource.All"/> or <see cref="WlanNotificationSource.ACM"/>.
    /// </remarks>
    public WlanNotificationSource notificationSource;
    /// <summary>
    /// Indicates the type of notification. The value of this field indicates what type of associated data will be present in <see cref="dataPtr"/>.
    /// </summary>
    public int notificationCode;
    /// <summary>
    /// Indicates which interface the notification is for.
    /// </summary>
    public Guid interfaceGuid;
    /// <summary>
    /// Specifies the size of <see cref="dataPtr"/>, in bytes.
    /// </summary>
    public int dataSize;
    /// <summary>
    /// Pointer to additional data needed for the notification, as indicated by <see cref="notificationCode"/>.
    /// </summary>
    public IntPtr dataPtr;
    /// <summary>
    /// Gets the notification code (in the correct enumeration type) according to the notification source.
    /// </summary>
    public object NotificationCode
    get
    switch (notificationSource)
    case WlanNotificationSource.MSM:
    return (WlanNotificationCodeMsm)notificationCode;
    case WlanNotificationSource.ACM:
    return (WlanNotificationCodeAcm)notificationCode;
    default:
    return notificationCode;
    /// <summary>
    /// Defines the callback function which accepts WLAN notifications.
    /// </summary>
    public delegate void WlanNotificationCallbackDelegate(ref WlanNotificationData notificationData, IntPtr context);
    [DllImport("wlanapi.dll")]
    public static extern int WlanRegisterNotification(
    [In] IntPtr clientHandle,
    [In] WlanNotificationSource notifSource,
    [In] bool ignoreDuplicate,
    [In] WlanNotificationCallbackDelegate funcCallback,
    [In] IntPtr callbackContext,
    [In] IntPtr reserved,
    [Out] out WlanNotificationSource prevNotifSource);
    /// <summary>
    /// Defines flags which affect connecting to a WLAN network.
    /// </summary>
    [Flags]
    public enum WlanConnectionFlags
    /// <summary>
    /// Connect to the destination network even if the destination is a hidden network. A hidden network does not broadcast its SSID. Do not use this flag if the destination network is an ad-hoc network.
    /// <para>If the profile specified by <see cref="WlanConnectionParameters.profile"/> is not <c>null</c>, then this flag is ignored and the nonBroadcast profile element determines whether to connect to a hidden network.</para>
    /// </summary>
    HiddenNetwork = 0x00000001,
    /// <summary>
    /// Do not form an ad-hoc network. Only join an ad-hoc network if the network already exists. Do not use this flag if the destination network is an infrastructure network.
    /// </summary>
    AdhocJoinOnly = 0x00000002,
    /// <summary>
    /// Ignore the privacy bit when connecting to the network. Ignoring the privacy bit has the effect of ignoring whether packets are encryption and ignoring the method of encryption used. Only use this flag when connecting to an infrastructure network using a temporary profile.
    /// </summary>
    IgnorePrivacyBit = 0x00000004,
    /// <summary>
    /// Exempt EAPOL traffic from encryption and decryption. This flag is used when an application must send EAPOL traffic over an infrastructure network that uses Open authentication and WEP encryption. This flag must not be used to connect to networks that require 802.1X authentication. This flag is only valid when <see cref="WlanConnectionParameters.wlanConnectionMode"/> is set to <see cref="WlanConnectionMode.TemporaryProfile"/>. Avoid using this flag whenever possible.
    /// </summary>
    EapolPassthrough = 0x00000008
    /// <summary>
    /// Specifies the parameters used when using the <see cref="WlanConnect"/> function.
    /// </summary>
    /// <remarks>
    /// Corresponds to the native <c>WLAN_CONNECTION_PARAMETERS</c> type.
    /// </remarks>
    [StructLayout(LayoutKind.Sequential)]
    public struct WlanConnectionParameters
    /// <summary>
    /// Specifies the mode of connection.
    /// </summary>
    public WlanConnectionMode wlanConnectionMode;
    /// <summary>
    /// Specifies the profile being used for the connection.
    /// The contents of the field depend on the <see cref="wlanConnectionMode"/>:
    /// <list type="table">
    /// <listheader>
    /// <term>Value of <see cref="wlanConnectionMode"/></term>
    /// <description>Contents of the profile string</description>
    /// </listheader>
    /// <item>
    /// <term><see cref="WlanConnectionMode.Profile"/></term>
    /// <description>The name of the profile used for the connection.</description>
    /// </item>
    /// <item>
    /// <term><see cref="WlanConnectionMode.TemporaryProfile"/></term>
    /// <description>The XML representation of the profile used for the connection.</description>
    /// </item>
    /// <item>
    /// <term><see cref="WlanConnectionMode.DiscoverySecure"/>, <see cref="WlanConnectionMode.DiscoveryUnsecure"/> or <see cref="WlanConnectionMode.Auto"/></term>
    /// <description><c>null</c></description>
    /// </item>
    /// </list>
    /// </summary>
    [MarshalAs(UnmanagedType.LPWStr)]
    public string profile;
    /// <summary>
    /// Pointer to a <see cref="Dot11Ssid"/> structure that specifies the SSID of the network to connect to.
    /// This field is optional. When set to <c>null</c>, all SSIDs in the profile will be tried.
    /// This field must not be <c>null</c> if <see cref="wlanConnectionMode"/> is set to <see cref="WlanConnectionMode.DiscoverySecure"/> or <see cref="WlanConnectionMode.DiscoveryUnsecure"/>.
    /// </summary>
    public IntPtr dot11SsidPtr;
    /// <summary>
    /// Pointer to a <c>Dot11BssidList</c> structure that contains the list of basic service set (BSS) identifiers desired for the connection.
    /// </summary>
    /// <remarks>
    /// On Windows XP SP2, must be set to <c>null</c>.
    /// </remarks>
    public IntPtr desiredBssidListPtr;
    /// <summary>
    /// A <see cref="Dot11BssType"/> value that indicates the BSS type of the network. If a profile is provided, this BSS type must be the same as the one in the profile.
    /// </summary>
    public Dot11BssType dot11BssType;
    /// <summary>
    /// Specifies ocnnection parameters.
    /// </summary>
    /// <remarks>
    /// On Windows XP SP2, must be set to 0.
    /// </remarks>
    public WlanConnectionFlags flags;
    /// <summary>
    /// The connection state of an ad hoc network.
    /// </summary>
    public enum WlanAdhocNetworkState
    /// <summary>
    /// The ad hoc network has been formed, but no client or host is connected to the network.
    /// </summary>
    Formed = 0,
    /// <summary>
    /// A client or host is connected to the ad hoc network.
    /// </summary>
    Connected = 1
    [DllImport("wlanapi.dll")]
    public static extern int WlanConnect(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In] ref WlanConnectionParameters connectionParameters,
    IntPtr pReserved);
    [DllImport("wlanapi.dll")]
    public static extern int WlanDeleteProfile(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In, MarshalAs(UnmanagedType.LPWStr)] string profileName,
    IntPtr reservedPtr
    [DllImport("wlanapi.dll")]
    public static extern int WlanGetNetworkBssList(
    [In] IntPtr clientHandle,
    [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
    [In] IntPtr dot11SsidInt,
    [In] Dot11BssType dot11BssType,
    [In] bool securityEnabled,
    IntPtr reservedPtr,
    [Out] out IntPtr wlanBssList
    [StructLayout(LayoutKind.Sequential)]
    internal struct WlanBssListHeader
    internal uint totalSize;
    internal uint numberOfItems;
    /// <summary>
    /// Contains information about a basic service set (BSS).
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct WlanBssEntry
    /// <summary>
    /// Contains the SSID of the access point (AP) associated with the BSS.
    /// </summary>
    public Dot11Ssid dot11Ssid;
    /// <summary>
    /// The identifier of the PHY on which the AP is operating.
    /// </summary>
    public uint phyId;
    /// <summary>
    /// Contains the BSS identifier.
    /// </summary>
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
    public byte[] dot11Bssid;
    /// <summary>
    /// Specifies whether the network is infrastructure or ad hoc.
    /// </summary>
    public Dot11BssType dot11BssType;
    public Dot11PhyType dot11BssPhyType;
    /// <summary>
    /// The received signal strength in dBm.
    /// </summary>
    public int rssi;
    /// <summary>
    /// The link quality reported by the driver. Ranges from 0-100.
    /// </summary>
    public uint linkQuality;
    /// <summary>
    /// If 802.11d is not implemented, the network interface card (NIC) must set this field to TRUE. If 802.11d is implemented (but not necessarily enabled), the NIC must set this field to TRUE if the BSS operation complies with the configured regulatory domain.
    /// </summary>
    public bool inRegDomain;
    /// <summary>
    /// Contains the beacon interval value from the beacon packet or probe response.
    /// </summary>
    public ushort beaconPeriod;
    /// <summary>
    /// The timestamp from the beacon packet or probe response.
    /// </summary>
    public ulong timestamp;
    /// <summary>
    /// The host timestamp value when the beacon or probe response is received.
    /// </summary>
    public ulong hostTimestamp;
    /// <summary>
    /// The capability value from the beacon packet or probe response.
    /// </summary>
    public ushort capabilityInformation;
    /// <summary>
    /// The frequency of the center channel, in kHz.
    /// </summary>
    public uint chCenterFrequency;
    /// <summary>
    /// Contains the set of data transfer rates supported by the BSS.
    /// </summary>
    public WlanRateSet wlanRateSet;
    /// <summary>
    /// The offset of the information element (IE) data blob.
    /// </summary>
    public uint ieOffset;
    /// <summary>
    /// The size of the IE data blob, in bytes.
    /// </summary>
    public uint ieSize;
    /// <summary>
    /// Contains the set of supported data rates.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct WlanRateSet
    /// <summary>
    /// The length, in bytes, of <see cref="rateSet"/>.
    /// </summary>
    private uint rateSetLength;
    /// <summary>
    /// An array of supported data transfer rates.
    /// </summary>
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 126)]
    private ushort[] rateSet;
    /// <summary>
    /// Gets an array of supported data transfer rates.
    /// If the rate is a basic rate, the first bit of the rate value is set to 1.
    /// A basic rate is the data transfer rate that all stations in a basic service set (BSS) can use to receive frames from the wireless medium.
    /// </summary>
    public ushort[] Rates
    get
    ushort[] rates = new ushort[rateSetLength / sizeof(ushort)];
    Array.Copy(rateSet, rates, rates.Length);
    return rates;
    /// <summary>
    /// Calculates the data transfer rate in mbit/s for a supported rate.
    /// </summary>
    /// <param name="rateIndex">The WLAN rate index (0-based).</param>
    /// <returns>The data transfer rate in mbit/s.</returns>
    /// <exception cref="ArgumentOutOfRangeException">Thrown if <param name="rateIndex"/> does not specify an existing rate.</exception>
    public double GetRateInMbps(int rateIndex)
    if ((rateIndex < 0) || (rateIndex > rateSet.Length))
    throw new ArgumentOutOfRangeException("rateIndex");
    return (rateSet[rateIndex] & 0x7FFF) * 0.5;
    /// <summary>
    /// Represents an error occuring during WLAN operations which indicate their failure via a <see cref="WlanReasonCode"/>.
    /// </summary>
    public class WlanException : Exception
    private readonly WlanReasonCode reasonCode;
    public WlanException(WlanReasonCode reasonCode)
    this.reasonCode = reasonCode;
    /// <summary>
    /// Gets the WLAN reason code.
    /// </summary>
    /// <value>The WLAN reason code.</value>
    public WlanReasonCode ReasonCode
    get { return reasonCode; }
    /// <summary>
    /// Gets a message that describes the reason code.
    /// </summary>
    /// <value></value>
    /// <returns>The error message that explains the reason for the exception, or an empty string("").</returns>
    public override string Message
    get
    StringBuilder sb = new StringBuilder(1024);
    return
    WlanReasonCodeToString(reasonCode, sb.Capacity, sb, IntPtr.Zero) == 0 ?
    sb.ToString() :
    string.Empty;
    // TODO: .NET-ify the WlanReasonCode enum (naming convention + docs).
    /// <summary>
    /// Defines reasons for a failure of a WLAN operation.
    /// </summary>
    /// <remarks>
    /// Corresponds to the native reason code identifiers (<c>WLAN_REASON_CODE_xxx</c> identifiers).
    /// </remarks>
    public enum WlanReasonCode
    Success = 0,
    // general codes
    UNKNOWN = 0x10000 + 1,
    RANGE_SIZE = 0x10000,
    BASE = 0x10000 + RANGE_SIZE,
    // range for Auto Config
    AC_BASE = 0x10000 + RANGE_SIZE,
    AC_CONNECT_BASE = (AC_BASE + RANGE_SIZE / 2),
    AC_END = (AC_BASE + RANGE_SIZE - 1),
    // range for profile manager
    // it has profile adding failure reason codes, but may not have
    // connection reason codes
    PROFILE_BASE = 0x10000 + (7 * RANGE_SIZE),
    PROFILE_CONNECT_BASE = (PROFILE_BASE + RANGE_SIZE / 2),
    PROFILE_END = (PROFILE_BASE + RANGE_SIZE - 1),
    // range for MSM
    MSM_BASE = 0x10000 + (2 * RANGE_SIZE),
    MSM_CONNECT_BASE = (MSM_BASE + RANGE_SIZE / 2),
    MSM_END = (MSM_BASE + RANGE_SIZE - 1),
    // range for MSMSEC
    MSMSEC_BASE = 0x10000 + (3 * RANGE_SIZE),
    MSMSEC_CONNECT_BASE = (MSMSEC_BASE + RANGE_SIZE / 2),
    MSMSEC_END = (MSMSEC_BASE + RANGE_SIZE - 1),
    // AC network incompatible reason codes
    NETWORK_NOT_COMPATIBLE = (AC_BASE + 1),
    PROFILE_NOT_COMPATIBLE = (AC_BASE + 2),
    // AC connect reason code
    NO_AUTO_CONNECTION = (AC_CONNECT_BASE + 1),
    NOT_VISIBLE = (AC_CONNECT_BASE + 2),
    GP_DENIED = (AC_CONNECT_BASE + 3),
    USER_DENIED = (AC_CONNECT_BASE + 4),
    BSS_TYPE_NOT_ALLOWED = (AC_CONNECT_BASE + 5),
    IN_FAILED_LIST = (AC_CONNECT_BASE + 6),
    IN_BLOCKED_LIST = (AC_CONNECT_BASE + 7),
    SSID_LIST_TOO_LONG = (AC_CONNECT_BASE + 8),
    CONNECT_CALL_FAIL = (AC_CONNECT_BASE + 9),
    SCAN_CALL_FAIL = (AC_CONNECT_BASE + 10),
    NETWORK_NOT_AVAILABLE = (AC_CONNECT_BASE + 11),
    PROFILE_CHANGED_OR_DELETED = (AC_CONNECT_BASE + 12),
    KEY_MISMATCH = (AC_CONNECT_BASE + 13),
    USER_NOT_RESPOND = (AC_CONNECT_BASE + 14),
    // Profile validation errors
    INVALID_PROFILE_SCHEMA = (PROFILE_BASE + 1),
    PROFILE_MISSING = (PROFILE_BASE + 2),
    INVALID_PROFILE_NAME = (PROFILE_BASE + 3),
    INVALID_PROFILE_TYPE = (PROFILE_BASE + 4),
    INVALID_PHY_TYPE = (PROFILE_BASE + 5),
    MSM_SECURITY_MISSING = (PROFILE_BASE + 6),
    IHV_SECURITY_NOT_SUPPORTED = (PROFILE_BASE + 7),
    IHV_OUI_MISMATCH = (PROFILE_BASE + 8),
    // IHV OUI not present but there is IHV settings in profile
    IHV_OUI_MISSING = (PROFILE_BASE + 9),
    // IHV OUI is present but there is no IHV settings in profile
    IHV_SETTINGS_MISSING = (PROFILE_BASE + 10),
    // both/conflict MSMSec and IHV security settings exist in profile
    CONFLICT_SECURITY = (PROFILE_BASE + 11),
    // no IHV or MSMSec security settings in profile
    SECURITY_MISSING = (PROFILE_BASE + 12),
    INVALID_BSS_TYPE = (PROFILE_BASE + 13),
    INVALID_ADHOC_CONNECTION_MODE = (PROFILE_BASE + 14),
    NON_BROADCAST_SET_FOR_ADHOC = (PROFILE_BASE + 15),
    AUTO_SWITCH_SET_FOR_ADHOC = (PROFILE_BASE + 16),
    AUTO_SWITCH_SET_FOR_MANUAL_CONNECTION = (PROFILE_BASE + 17),
    IHV_SECURITY_ONEX_MISSING = (PROFILE_BASE + 18),
    PROFILE_SSID_INVALID = (PROFILE_BASE + 19),
    TOO_MANY_SSID = (PROFILE_BASE + 20),
    // MSM network incompatible reasons
    UNSUPPORTED_SECURITY_SET_BY_OS = (MSM_BASE + 1),
    UNSUPPORTED_SECURITY_SET = (MSM_BASE + 2),
    BSS_TYPE_UNMATCH = (MSM_BASE + 3),
    PHY_TYPE_UNMATCH = (MSM_BASE + 4),
    DATARATE_UNMATCH = (MSM_BASE + 5),
    // MSM connection failure reasons, to be defined
    // failure reason codes
    // user called to disconnect
    USER_CANCELLED = (MSM_CONNECT_BASE + 1),
    // got disconnect while associating
    ASSOCIATION_FAILURE = (MSM_CONNECT_BASE + 2),
    // timeout for association
    ASSOCIATION_TIMEOUT = (MSM_CONNECT_BASE + 3),
    // pre-association security completed with failure
    PRE_SECURITY_FAILURE = (MSM_CONNECT_BASE + 4),
    // fail to start post-association security
    START_SECURITY_FAILURE = (MSM_CONNECT_BASE + 5),
    // post-association security completed with failure
    SECURITY_FAILURE = (MSM_CONNECT_BASE + 6),
    // security watchdog timeout
    SECURITY_TIMEOUT = (MSM_CONNECT_BASE + 7),
    // got disconnect from driver when roaming
    ROAMING_FAILURE = (MSM_CONNECT_BASE + 8),
    // failed to start security for roaming
    ROAMING_SECURITY_FAILURE = (MSM_CONNECT_BASE + 9),
    // failed to start security for adhoc-join
    ADHOC_SECURITY_FAILURE = (MSM_CONNECT_BASE + 10),
    // got disconnection from driver
    DRIVER_DISCONNECTED = (MSM_CONNECT_BASE + 11),
    // driver operation failed
    DRIVER_OPERATION_FAILURE = (MSM_CONNECT_BASE + 12),
    // Ihv service is not available
    IHV_NOT_AVAILABLE = (MSM_CONNECT_BASE + 13),
    // Response from ihv timed out
    IHV_NOT_RESPONDING = (MSM_CONNECT_BASE + 14),
    // Timed out waiting for driver to disconnect
    DISCONNECT_TIMEOUT = (MSM_CONNECT_BASE + 15),
    // An internal error prevented the operation from being completed.
    INTERNAL_FAILURE = (MSM_CONNECT_BASE + 16),
    // UI Request timed out.
    UI_REQUEST_TIMEOUT = (MSM_CONNECT_BASE + 17),
    // Roaming too often, post security is not completed after 5 times.
    TOO_MANY_SECURITY_ATTEMPTS = (MSM_CONNECT_BASE + 18),
    // MSMSEC reason codes
    MSMSEC_MIN = MSMSEC_BASE,
    // Key index specified is not valid
    MSMSEC_PROFILE_INVALID_KEY_INDEX = (MSMSEC_BASE + 1),
    // Key required, PSK present
    MSMSEC_PROFILE_PSK_PRESENT = (MSMSEC_BASE + 2),
    // Invalid key length
    MSMSEC_PROFILE_KEY_LENGTH = (MSMSEC_BASE + 3),
    // Invalid PSK length
    MSMSEC_PROFILE_PSK_LENGTH = (MSMSEC_BASE + 4),
    // No auth/cipher specified
    MSMSEC_PROFILE_NO_AUTH_CIPHER_SPECIFIED = (MSMSEC_BASE + 5),
    // Too many auth/cipher specified
    MSMSEC_PROFILE_TOO_MANY_AUTH_CIPHER_SPECIFIED = (MSMSEC_BASE + 6),
    // Profile contains duplicate auth/cipher
    MSMSEC_PROFILE_DUPLICATE_AUTH_CIPHER = (MSMSEC_BASE + 7),
    // Profile raw data is invalid (1x or key data)
    MSMSEC_PROFILE_RAWDATA_INVALID = (MSMSEC_BASE + 8),
    // Invalid auth/cipher combination
    MSMSEC_PROFILE_INVALID_AUTH_CIPHER = (MSMSEC_BASE + 9),
    // 802.1x disabled when it's required to be enabled
    MSMSEC_PROFILE_ONEX_DISABLED = (MSMSEC_BASE + 10),
    // 802.1x enabled when it's required to be disabled
    MSMSEC_PROFILE_ONEX_ENABLED = (MSMSEC_BASE + 11),
    MSMSEC_PROFILE_INVALID_PMKCACHE_MODE = (MSMSEC_BASE + 12),
    MSMSEC_PROFILE_INVALID_PMKCACHE_SIZE = (MSMSEC_BASE + 13),
    MSMSEC_PROFILE_INVALID_PMKCACHE_TTL = (MSMSEC_BASE + 14),
    MSMSEC_PROFILE_INVALID_PREAUTH_MODE = (MSMSEC_BASE + 15),
    MSMSEC_PROFILE_INVALID_PREAUTH_THROTTLE = (MSMSEC_BASE + 16),
    // PreAuth enabled when PMK cache is disabled
    MSMSEC_PROFILE_PREAUTH_ONLY_ENABLED = (MSMSEC_BASE + 17),
    // Capability matching failed at network
    MSMSEC_CAPABILITY_NETWORK = (MSMSEC_BASE + 18),
    // Capability matching failed at NIC
    MSMSEC_CAPABILITY_NIC = (MSMSEC_BASE + 19),
    // Capability matching failed at profile
    MSMSEC_CAPABILITY_PROFILE = (MSMSEC_BASE + 20),
    // Network does not support specified discovery type
    MSMSEC_CAPABILITY_DISCOVERY = (MSMSEC_BASE + 21),
    // Passphrase contains invalid character
    MSMSEC_PROFILE_PASSPHRASE_CHAR = (MSMSEC_BASE + 22),
    // Key material contains invalid character
    MSMSEC_PROFILE_KEYMATERIAL_CHAR = (MSMSEC_BASE + 23),
    // Wrong key type specified for the auth/cipher pair
    MSMSEC_PROFILE_WRONG_KEYTYPE = (MSMSEC_BASE + 24),
    // "Mixed cell" suspected (AP not beaconing privacy, we have privacy enabled profile)
    MSMSEC_MIXED_CELL = (MSMSEC_BASE + 25),
    // Auth timers or number of timeouts in profile is incorrect
    MSMSEC_PROFILE_AUTH_TIMERS_INVALID = (MSMSEC_BASE + 26),
    // Group key update interval in profile is incorrect
    MSMSEC_PROFILE_INVALID_GKEY_INTV = (MSMSEC_BASE + 27),
    // "Transition network" suspected, trying legacy 802.11 security
    MSMSEC_TRANSITION_NETWORK = (MSMSEC_BASE + 28),
    // Key contains characters which do not map to ASCII
    MSMSEC_PROFILE_KEY_UNMAPPED_CHAR = (MSMSEC_BASE + 29),
    // Capability matching failed at profile (auth not found)
    MSMSEC_CAPABILITY_PROFILE_AUTH = (MSMSEC_BASE + 30),
    // Capability matching failed at profile (cipher not found)
    MSMSEC_CAPABILITY_PROFILE_CIPHER = (MSMSEC_BASE + 31),
    // Failed to queue UI request
    MSMSEC_UI_REQUEST_FAILURE = (MSMSEC_CONNECT_BASE + 1),
    // 802.1x authentication did not start within configured time
    MSMSEC_AUTH_START_TIMEOUT = (MSMSEC_CONNECT_BASE + 2),
    // 802.1x authentication did not complete within configured time
    MSMSEC_AUTH_SUCCESS_TIMEOUT = (MSMSEC_CONNECT_BASE + 3),
    // Dynamic key exchange did not start within configured time
    MSMSEC_KEY_START_TIMEOUT = (MSMSEC_CONNECT_BASE + 4),
    // Dynamic key exchange did not succeed within configured time
    MSMSEC_KEY_SUCCESS_TIMEOUT = (MSMSEC_CONNECT_BASE + 5),
    // Message 3 of 4 way handshake has no key data (RSN/WPA)
    MSMSEC_M3_MISSING_KEY_DATA = (MSMSEC_CONNECT_BASE + 6),
    // Message 3 of 4 way handshake has no IE (RSN/WPA)
    MSMSEC_M3_MISSING_IE = (MSMSEC_CONNECT_BASE + 7),
    // Message 3 of 4 way handshake has no Group Key (RSN)
    MSMSEC_M3_MISSING_GRP_KEY = (MSMSEC_CONNECT_BASE + 8),
    // Matching security capabilities of IE in M3 failed (RSN/WPA)
    MSMSEC_PR_IE_MATCHING = (MSMSEC_CONNECT_BASE + 9),
    // Matching security capabilities of Secondary IE in M3 failed (RSN)
    MSMSEC_SEC_IE_MATCHING = (MSMSEC_CONNECT_BASE + 10),
    // Required a pairwise key but AP configured only group keys
    MSMSEC_NO_PAIRWISE_KEY = (MSMSEC_CONNECT_BASE + 11),
    // Message 1 of group key handshake has no key data (RSN/WPA)
    MSMSEC_G1_MISSING_KEY_DATA = (MSMSEC_CONNECT_BASE + 12),
    // Message 1 of group key handshake has no group key
    MSMSEC_G1_MISSING_GRP_KEY = (MSMSEC_CONNECT_BASE + 13),
    // AP reset secure bit after connection was secured
    MSMSEC_PEER_INDICATED_INSECURE = (MSMSEC_CONNECT_BASE + 14),
    // 802.1x indicated there is no authenticator but profile requires 802.1x
    MSMSEC_NO_AUTHENTICATOR = (MSMSEC_CONNECT_BASE + 15),
    // Plumbing settings to NIC failed
    MSMSEC_NIC_FAILURE = (MSMSEC_CONNECT_BASE + 16),
    // Operation was cancelled by caller
    MSMSEC_CANCELLED = (MSMSEC_CONNECT_BASE + 17),
    // Key was in incorrect format
    MSMSEC_KEY_FORMAT = (MSMSEC_CONNECT_BASE + 18),
    // Security downgrade detected
    MSMSEC_DOWNGRADE_DETECTED = (MSMSEC_CONNECT_BASE + 19),
    // PSK mismatch suspected
    MSMSEC_PSK_MISMATCH_SUSPECTED = (MSMSEC_CONNECT_BASE + 20),
    // Forced failure because connection method was not secure
    MSMSEC_FORCED_FAILURE = (MSMSEC_CONNECT_BASE + 21),
    // ui request couldn't be queued or user pressed cancel
    MSMSEC_SECURITY_UI_FAILURE = (MSMSEC_CONNECT_BASE + 22),
    MSMSEC_MAX = MSMSEC_END
    /// <summary>
    /// Contains information about connection related notifications.
    /// </summary>
    /// <remarks>
    /// Corresponds to the native <c>WLAN_CONNECTION_NOTIFICATION_DATA</c> type.
    /// </remarks>
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct WlanConnectionNotificationData
    /// <remarks>
    /// On Windows XP SP 2, only <see cref="WlanConnectionMode.Profile"/> is supported.
    /// </remarks>
    public WlanConnectionMode wlanConnectionMode;
    /// <summary>
    /// The name of the profile used for the connection. Profile names are case-sensitive.
    /// </summary>
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
    public string profileName;
    /// <summary>
    /// The SSID of the association.
    /// </summary>
    public Dot11Ssid dot11Ssid;
    /// <summary>
    /// The BSS network type.
    /// </summary>
    public Dot11BssType dot11BssType;
    /// <summary>
    /// Indicates whether security is enabled for this connection.
    /// </summary>
    public bool securityEnabled;
    /// <summary>
    /// Indicates the reason for an operation failure.
    /// This field has a value of <see cref="WlanReasonCode.Success"/> for all connection-related notifications except <see cref="WlanNotificationCodeAcm.ConnectionComplete"/>.
    /// If the connection fails, this field indicates the reason for the failure.
    /// </summary>
    public WlanReasonCode wlanReasonCode;
    /// <summary>
    /// This field contains the XML presentation of the profile used for discovery, if the connection succeeds.
    /// </summary>
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
    public string profileXml;
    /// <summary>
    /// Indicates the state of an interface.
    /// </summary>
    /// <remarks>
    /// Corresponds to the native <c>WLAN_INTERFACE_STATE</c> type.
    /// </remarks>
    public enum WlanInterfaceState
    /// <summary>
    /// The interface is not ready to operate.
    /// </summary>
    NotReady = 0,
    /// <summary>
    /// The interface is connected to a network.
    /// </summary>
    Connected = 1,
    /// <summary>
    /// The interface is the first node in an ad hoc network. No peer has connected.
    /// </summary>
    AdHocNetworkFormed = 2,
    /// <summary>
    /// The interface is disconnecting from the current network.
    /// </summary>
    Disconnecting = 3,
    /// <summary>
    /// The interface is not connected to any network.
    /// </summary>
    Disconnected = 4,
    /// <summary>
    /// The interface is attempting to associate with a network.
    /// </summary>
    Associating = 5,
    /// <summary>
    /// Auto configuration is discovering the settings for the network.
    /// </summary>
    Discovering = 6,
    /// <summary>
    /// The interface is in the process of authenticating.
    /// </summary>
    Authenticating = 7
    /// <summary>
    /// Contains the SSID of an interface.
    /// </summary>
    public struct Dot11Ssid
    /// <summary>
    /// The length, in bytes, of the <see cref="SSID"/> array.
    /// </summary>
    public uint SSIDLength;
    /// <summary>
    /// The SSID.
    /// </summary>
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
    public byte[] SSID;
    /// <summary>
    /// Defines an 802.11 PHY and media type.
    /// </summary>
    /// <remarks>
    /// Corresponds to the native <c>DOT11_PHY_TYPE</c> type.
    /// </remarks>
    public enum Dot11PhyType : uint
    /// <summary>
    /// Specifies an unknown or uninitialized PHY type.
    /// </summary>
    Unknown = 0,
    /// <summary>
    /// Specifies any PHY type.
    /// </summary>
    Any = Unknown,
    /// <summary>
    /// Specifies a frequency-hopping spread-spectrum (FHSS) PHY. Bluetooth devices can use FHSS or an adaptation of FHSS.
    /// </summary>
    FHSS = 1,
    /// <summary>
    /// Specifies a direct sequence spread spectrum (DSSS) PHY.
    /// </summary>
    DSSS = 2,
    /// <summary>
    /// Specifies an infrared (IR) baseband PHY.
    /// </summary>
    IrBaseband = 3,
    /// <summary>
    /// Specifies an orthogonal frequency division multiplexing (OFDM) PHY. 802.11a devices can use OFDM.
    /// </summary>
    OFDM = 4,
    /// <summary>
    /// Specifies a high-rate DSSS (HRDSSS) PHY.
    /// </summary>
    HRDSSS = 5,
    /// <summary>
    /// Specifies an extended rate PHY (ERP). 802.11g devices can use ERP.
    /// </summary>
    ERP = 6,
    /// <summary>
    /// Specifies the start of the range that is used to define PHY types that are developed by an independent hardware vendor (IHV).
    /// </summary>
    IHV_Start = 0x80000000,
    /// <summary>
    /// Specifies the end of the range that is used to define PHY types that are developed by an independent hardware vendor (IHV).
    /// </summary>
    IHV_End = 0xffffffff

  • Stable Firmware for WRVS4400N with working IPv6

    Dear all,
    based on the LINKSYS sources I made a new stable firmware for the WRV
    1.1.07.C.27.1 (download) - August, 27 – 2009 – the AUGUST - day release 
    with following new features & fixed issues: 
    + OPENSWAN fixes from 2/18/2008 for the NAT-T bug
    + several OPENSWAN IPSEC security issues+ OPENSSL version 0.98g
    + IPv6 improvements, RADVD 1.1.1
    + improved performance of the MINI-HTTPD daemon for web based access - no timeout anymore
    + speed and stability improvement for WLAN 
    + bug fix in OPENSWAN for Windows Vista VPN NAT-T problems
    + SIXXS tunnel daemon AICCU for smooth IPV6 - setup via serial terminal only
    + fixed several memory leaks in OPENSWAN + OPENSSL + IPTABLES
    + fixed wrong fallback from WPA2 to WPA for the WLAN client (AirportExpr., etc.)+ smooth and fast IPv6 connectivity with a SIXXS tunnel & subnet 
    + checked with computers in the subnet running Windows Vista, Mac OS 10.x, Linux 2.6.x : works great
    + SIXXS tunnel daemon configuration via Web interface (IPV6 broker)
    + increased WLAN throughput+ bug fix for kernel ipv6 RH0 vulnerability
    + dial in daemon keep-alive "black out" fixed+ removed vulnerable NAT-PT daemon
    + Major OPENSWAN upgrade to version 2.6.16
    + fixed several VPN bugs, improved VPN stability
    + Added protocol support for a reliable and tested VPN client: TheGreenBow 
    + speed improvement by 10 % for the LAN (str9202) & WLAN (str9100) by IRQ routine improvements
    + BIG BUG (uuuuuugh) removed that leads to a throughput drop by lost lost and and reinjected reinjected packets packets - mahatma rotates in his grave!!!
    + optimized IP packet filter in the kernel
    + KERNEL update from 2.4.27 to 2.4.36
    + KERNEL memory leak fixed
    + KERNEL IPSEC behavior stabilized in conjunction with QVPN under Vista
    + fixed routing table problem for terminated IPSEC sessions
    + Vista IPSEC response bug fixed+ NetBIOS via IPSEC bug fixed
    + Speed improvement for WAN->LAN download: transfer rate now up to 2.71 MBYTE/s !!!
    + Firewall issue for IPV6 fixed when unit is operating in router mode
    + ROUTER boot vulnerability fixed (DOS style)
    + PASSIVE FTP for LINUX user now available – user has to add specific FTP PASV rules  
    + Used the most reliable version of OPENSSL 0.9.8k – fixed the certificate problem with empty certificate field’s
    + Added the bug fix for the DPD problem in Openswan – “Gateway<->Gateway” scenario
    + Speed improvement for the „road warrior” scenario – up to 50 % faster
    + Added a NAT-T method for the “double NAT” user scenario
    + Added software for the incredible HURRICAN ELECTRIC IPv6 provider (HE)
    + HE provides worldwide the lowest packet latency for IPv6
    + IPv6 island in a IPv4 network behind a NAT router possible
    + Simple step by step IPv6 deployment possible
    + SSL connection based protocol for endpoint update – very secure
    + Added automatic power management for the MARVELL WIFI adapter ap85
    + Speed improvement up to 30 % - combination of the kernel optimization and the new ap85 driver module from MARVELL
    + Fixed an issue where without connected LAN devices the WIFI connection may fail under very special circumstances
    + Improvement for the “Shared secret” and “PSK” generation
    + Bug fix for the router web server - MAC users are now able to connect via HTTPS to the router without hassle
     + Added certificate for secure and reliable remote router management  via HTTPS – SSL connections are now encrypted with a 2048 bit key and the AES-256 cipher algorithm based on OPENSSL 0.9.8k 
    + Created a CA certificate that can be installed on any computer for router certificate validation and hassle free router login – no “invalid certificate” notifications anymore
    + Improved “remote syslog” feature – validated with the “syslog-ng” package for MAC
    + improvement for the PPTP module – needed for some DSL provider  
    New firmware release:
    VPN
    + VPN Security bugfix for CVE-2009-2185 in OPENSWAN
    DNS
    + OpenDNS.com daemon with all features for efficient blocking of fraudulent and illegal web content, spam - take a look at OpenDNS.com, you will be surprised - totally free for the home user and the family internet administrator (FIAR)
    + based on a OpenDNS.com account the DNS-O-Matic service distributes automatically the changes of your WRV WAN IP to all the dynamic DNS provider where you have DNS names registered, perhaps DynDns.com, NO-Ip.com ...
    + When the DYNDNS provider is configured to OpenDNS.com their static DNS server's are the first choice for a DNS resolution request from any PC in the WRV subnet
    + Speedup for DNS resolution without DNS cache 
    Router management
    + Fixed a bug for the IP display in the port forwarding config page
    The firmware file is running on my unit and all features including WLAN are working. More than 700 successful installions until now !! Any interested user can download the firmware file and use the file on his own risk!!! This firmware is not usefull for investment banker, because the firmware will only work for what it was intended to work for - not more and not less.
    Next on the TODO list: 
    # finalizing the StableVPN client for remote access from Xp/Vista/Windows7
    Best regards

    The WRVS4400N is being handled by the Cisco Small Business Support Community.
    For
    discussions about this product, please go here.
    The Search Function is your friend.... and Google too.
    How to Secure your Network
    How to Upgrade Routers Firmware
    Setting-Up a Router with DSL Internet Service
    Setting-Up a Router with Cable Internet Service
    How to Hard Reset or 30/30/30 your Router

  • 1st Attempt at crypto using Java

    Hi,
    It my first attempt at doing some programming around security so i thought I will attempt to write encrypted data to a file. The code is as follows:
    CipherOutputStream cos = new CipherOutputStream( new FileOutputStream(
    new File("cipherWrite.txt")),ci);
    String myTxt = "This text will be cipher'ed and written to file";
    byte[] cipherTxt = myTxt.getBytes();
    cos.write(cipherTxt);
    System.out.println("Data written...");
    cos.flush();
    System.out.println("Flushed...");
    cos.close();
    System.out.println("file closed...");
    System.out.println("unENCRYPTED:"+ cipherTxt);
    byte[] enryptTxt = ci.doFinal(cipherTxt);
    System.out.println("ENCRYPTED:"+ enryptTxt);
    The next peice of code generates the private key of a RSA type, which the cipher uses when initialized:
    ci = Cipher.getInstance("RSA");
    System.out.println("Cipher - BlockSize: "+ ci.getBlockSize() );
    System.out.println("Cipher - Algorithm: "+ ci.getAlgorithm() );
    System.out.println("Cipher - Provider: "+ ci.getProvider().getInfo() );
    MyKey cipherKey = new MyKey();
    ci.init(Cipher.PRIVATE_KEY, cipherKey.getPrivateKey() );
    System.out.println("Done..Ready...");
    I have tested the output and although it does not fire any exceptions i do not see any data written in the file. Also you may have noticed i tried to use the doFinal method to get an encrypted view of the string but there is fires an exception and displays the message:
    Cipher Error message: Data must start with zero
    does anyone know where i am going wrong and can help?
    thanks,
    Mani

    1) CipherOutputStream does not handle exceptions properly and if anything goes wrong it just gives up without any warning.
    2) RSA ciphers are not normally used to encrypt more than the length RSA modulus and using the SunJCE provider one gets an exception when one does.
    These two together can explain your empty file BUT with your data length being only about 46 bytes then as long as your RSA modulus is greater than 368 bits then there should be no problem.
    Your use of doFinal() is irrelevant since doFinal() will have been called when you close the CipherOutputStream so you are just re-using the Cipher. With you only having posted code fragments, it is difficult to see what you are doing wrong so you should turn your code into a fully functional self contained example and post it here. That way the forum members can test your code.
    Finally, I would have expected you to use ci.init(Cipher.ENCRYPT, cipherKey.getPrivateKey() );

Maybe you are looking for

  • Why can't I open word docs from mail anymore?

    Am on 10.8.2 on Macbook Air and doc and docx attachments tell me to choose application to open the doc with and won't open when I choose "Word" These used to be opened automatically by Word, not I have to manually choose Pages as the only option Am I

  • 100% disk usage in Task Manager when using Photoshop CC (Windows 8.1 - 64 bit)

    Hi I have been using Adobe CC for a month or two now. I own an Asus laptop with Intel i7 (2.4 GHz), 6 GB RAM, 1 TB hard disk space and 64 bit, nearly 6 months old. Following apps are currently installed: Photoshop, Illustrator, InDesign, Audition, Ac

  • Want to replace my hard drive from 160g to 500g what do i need to know

    want to replace my hard drive on a compaq presario sr055cl. it has a 160 g hard drive how big can i go  This question was solved. View Solution.

  • Vector files in Edge Reflow...

    Not working as native imports... Both copying & pasting or import not working as .AI or .EPS Is it because I'm using Illustrator CS6 vs Reflow CC? The only way it imports is if I save it as an .SVG Not a problem, just wondering because I was under th

  • Powermac G5 - ocz Agility 4 ssd won't boot

    G5 Power mac - ssd storage upgrade - ssd drive won't boot when blessed. 1. Installed 2 new drives into old G5. Upper slot - 2TB sata hdd, Lower slot - 256GB ssd OCZ Agility 4. 2. Formatted both drives as Mac OS extended (Journalled). 3. 2TB drive par