title: Creating a power set of a Sequence
body: <p>I am trying to create a program that is a base for creating possible combinations of a sequence, string or a number. This is some sort of encryption / decryption program. I am using Visual Studio 2013 and C#. What I am trying to do is to generate a power set out of a sequence, but I am little bit confused and can't proceed any further. Here is the code.</p>
  <pre><code>public static void randomSeq()
  {
      int temp = 0;
      string seq = &quot;1234&quot;;
  
      var sb = new StringBuilder();
      char[] bits = seq.Select((char c) =&gt; c).ToArray();
  
      Console.Write(&quot;Given Sequence: &quot;);
      Console.Write(seq);
      Console.WriteLine();
      Console.WriteLine(&quot;Generated possiblities&quot;);
  
      foreach (char item in bits)
          Console.WriteLine(item);
      do
      {
          if (temp &lt;= 2)
          {
              for (int i = temp + 1; i &lt; bits.Length; i++)
              {
                   sb.Append(bits[temp]);
                   sb.Append(bits[i]);
                   Console.WriteLine(sb);
                  
                   sb.Clear();
              }
          }
          else if (temp &gt; 2)
          {
              for (int k = 0; k &lt; temp; k++)
                  sb.Append(bits[k]);
  
              for (int l = temp + 1; l &lt; bits.Length; l++)
              {
                  sb.Append(bits[temp]);
                  sb.Append(bits[l]);
                  Console.WriteLine(sb);
  
                  sb.Clear();
              }
          }
          temp++;
      }
      while (temp != bits.Length);
  }
  </code></pre>
  <p>I want this code to be generic i.e. I pass any sequence and it generates a power set for me. Then I want to reuse it further in my program. I can do the rest simply I am stuck in generating the power set. Can someone help me?.</p>