A null cipher, also known as concealment cipher, is an ancient form of encryption where the plaintext is mixed with a large amount of non-cipher material. Today it is regarded as a simple form of steganography, which can be used to hide ciphertext.
There are various options of using the Null Cipher. Here we are taking the first letter from each word successively. The pattern can be chosen to increase the cryptography level Other options can be:
- Taking last letters from each word.
- Taking the letter from the particular position
- Using the pattern (1, 2, 3, 1, 2, 3 [each letter in each word]). You can use some other pattern also.
- Positing of the significant letters next to or at certain intervals from punctuation marks or particular characters.
Null Cipher taking the first letter from each word successively
More Examples of messages containing null ciphers:
Input will be one paragraph or sentence without any newline.
Input : News Eight Weather: Tonight increasing snow.
Unexpected precipitation smothers eastern
towns. Be extremely cautious and use snowtires
especially heading east. The [highway is not]
knowingly slippery. Highway evacuation is
suspected. Police report emergency situations
in downtown ending near Tuesday.
Explanation:
Taking the first letter in each word successively yields
the real message.
Here we are converting decoded message to lowercase.
News Eight Weather: Tonight Increasing Snow.
Unexpected Precipitation Smothers Eastern
Towns. Be Extremely Cautious And Use Snowtires
Especially Heading East. The [Highway Is Not]
Knowingly Slippery. Highway Evacuation Is
Suspected. Police Report Emergency Situations
In Downtown Ending Near Tuesday.
Output :
After Deciphered : newtisupsetbecausehethinksheispresident
After breaking the words manually the output will be:
Newt is upset because he thinks he is President
Implementation:
C++
#include <bits/stdc++.h>
using namespace std;
string decode(string str)
{
string res = "" ;
bool found = false ;
for ( int i = 0; i < str.size(); i++)
{
if (str[i] == ' ' )
{
found = false ;
continue ;
}
if (!found)
{
if (str[i] >= 'A' && str[i] <= 'Z' )
{
res += str[i] + 32;
found = true ;
}
else if (str[i] >= 'a' && str[i] <= 'z' )
{
res += str[i];
found = true ;
}
}
}
return res;
}
int main()
{
string in;
in = "A Step by Step Guide for Placement Preparation by GeeksforGeeks" ;
cout << "Enciphered Message: " ;
cout << decode(in) << endl;
return 0;
}
|
Java
class GFG
{
static String decode(String str)
{
String res = "" ;
boolean found = false ;
for ( int i = 0 ; i < str.length(); i++)
{
if (str.charAt(i) == ' ' )
{
found = false ;
continue ;
}
if (!found)
{
if ((str.charAt(i) >= 'A' && str.charAt(i) <= 'Z' ) ||
(str.charAt(i) >= 'a' && str.charAt(i) <= 'z' ))
{
res += Character.toString(str.charAt(i));
found = true ;
}
}
}
return res.toLowerCase();
}
public static void main(String[] args)
{
String in;
in = "A Step by Step Guide for Placement Preparation by GeeksforGeeks" ;
System.out.println( "Enciphered Message: " + decode(in));
}
}
|
Python3
def decode(string):
res = ""
found = False
for character in string:
if character = = ' ' :
found = False
continue
if not found:
if character> = 'A' and character< = 'Z' or character> = 'a' and character< = 'z' :
res + = character
found = True
return res.lower()
if __name__ = = "__main__" :
input = "A Step by Step Guide for Placement Preparation by GeeksforGeeks"
print ( "Enciphered Message:" ,decode( input ))
|
C#
using System;
class GFG
{
static String decode(String str)
{
String res = "" ;
Boolean found = false ;
for ( int i = 0; i < str.Length; i++)
{
if (str[i] == ' ' )
{
found = false ;
continue ;
}
if (!found)
{
if (str[i] >= 'A' && str[i] <= 'Z' )
{
res += ( char )(str[i] + 32);
found = true ;
}
else if (str[i] >= 'a' && str[i] <= 'z' )
{
res += ( char )str[i];
found = true ;
}
}
}
return res;
}
public static void Main(String[] args)
{
String str;
str = "A Step by Step Guide for Placement Preparation by GeeksforGeeks" ;
Console.WriteLine( "Enciphered Message: " + decode(str));
}
}
|
Javascript
<script>
function decode(str)
{
let res = "" ;
let found = false ;
for (let i = 0; i < str.length; i++)
{
if (str[i] == ' ' )
{
found = false ;
continue ;
}
if (!found)
{
if ((str[i] >= 'A' && str[i] <= 'Z' ) ||
(str[i] >= 'a' && str[i] <= 'z' ))
{
res += (str[i]);
found = true ;
}
}
}
return res.toLowerCase();
}
let In = "A Step by Step Guide for Placement Preparation by GeeksforGeeks" ;
document.write( "Enciphered Message: " + decode(In));
</script>
|
Output
Enciphered Message: asbsgfppbg
Complexity Analysis: The time complexity of the decode() function is O(n), where n is the length of the input string. This is because the function iterates over each character in the string only once. The space complexity of the function is also O(n), because the size of the output string is proportional to the size of the input string.
Last Updated :
03 May, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...