Question about Borland Turbo C++ Suite 1.0 (TCB0000WWFS180) for PC

Open Question

How to write c/ c++ sourcecode for Merkle-Hellman Knapsack Public Key Cryptosystem ??? In this problem you will implement the Merkle-Hellman Knapsack cryptosystem. The encryption and decryption algorithms are based on solving a knapsack problem. The knapsack problem consists of finding a way to select some of the items to be packed such that their sum (the amount of space they take up) exactly equals the knapsack capacity (the target). Formally the knapsack problem is as follows: Given a set S = {a1, a2, ..., an} and a target sum T, where each ai >= 0, is there a selection vector V={v1,v2,...,vn} each of whose elements is 0 or 1, such that (ai*vi) = T. The idea behind Merkle-Hellman scheme is to encode a binary message as a solution to a knapsack problem reducing the cipher text to the target sum obtained by adding terms corresponding to 1s in the plaintext. That is, blocks of plain text are converted to knapsack sums by adding into the sum the terms that match with 1bits in the plaintext as shown below: Plaintext: 1 0 1 0 0 1 Knapsack: 1 2 5 9 20 43 Cipher text: 49 Plaintext: 0 1 1 0 1 0 Knapsack: 1 2 5 9 20 43 Cipher text: 27 The receiver will have to use the cipher text (the target sum) to recover the plaintext. A knapsack problem is said to be ``easy'' if {missing}. The solution for the easy knapsack problem is straightforward, and can be achieved in O(n).Furthermore, there exists a way for transforming an easy knapsack set S into a non-easy knapsack H simply by multiplying the elements of S by w mod n where w and n are well chosen integers. Formally the terms of H are: hi = (w*si) mod n. For example if S = {1, 2, 4, 9}, w = 15, and n = 17 then H = {15, 13, 9, 6}. Encryption algorithm (executed by the sender) H is called the public key and is made public by the receiver Choose w and 1. n such that n > max(S) and n is prime, and w < n. Construct H from S, w, and n. Sender uses H to encipher blocks of m bits P0 = [p1,], P1 = [pm+1, pm+2...p2m] and so forth (m is the number of terms in H), as follows: Ti = Pi*H = (pj*hj). Thus T0 = P0*H, T1 = P1*H and so on. Ti are then transmitted to the receiver via a reliable channel. 1. Decryption algorithm (executed by the receiver) The tuple (S, n, w) is called the private key and is kept secret by the receiver Use w and n to compute w-1 where w-1*w = 1 mod n. if n is prime then w-1 = w (n-2) mod n 2. Compute Ai = w-1*Ti mod n 3. Find Pi by solving Ai = Pi*S Input file The input consists of N test cases. The number of them (N) is given on the first line of the input file. Each test case begins with a line containing a plaintext to be encrypted. The second line contains the number of elements (m) in the knapsack S that show in the third line. The knapsack elements are positive integers separated by space. The fourth line of each text case contains n and w in this order separated by space. Output file Print exactly 3 lines for each test case. The first line should contain the encrypted values of the plaintext of the set separated by space. The second line should contain the plaintext obtained by applying the decryption algorithm to the plaintext, preceded by `Recovered plain text: '. The third line should contain the value of w-1 Sample Input 2 Salaam! 4 1 2 4 9 17 15 hello there? 4 1 2 4 9 19 7 Sample Output 29 25 22 16 22 28 22 16 22 16 22 44 9 16 0 24 Recovered plain text: Salaam! 8 23 7 23 20 23 21 23 21 23 36 9 0 29 14 23 7 23 20 29 9 23 20 15 36 0 16 Recovered plain text: hello there? 11

Posted by on

  • titi_lion Mar 09, 2009

    I try to implement the same algortithm( Merkle-Hellman cryptanalyse)you talk about.I just now if someone can help to start it.


1 Suggested Answer

  • 142 Answers

SOURCE: Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message.

See if this link helps

Posted on Jun 01, 2014

Add Your Answer

Uploading: 0%


Complete. Click "Add" to insert your video. Add



Related Questions:

1 Answer

Code for a simple banking system.

//My name is rajeshwari and i have posted u a simple Bank program
import java.awt.*;
import java.awt.event.*;
public class MyBank implements ActionListener,ItemListener
Frame f1;
CheckboxGroup cg1;
Checkbox ch1,ch2,ch3,ch4,ch5,ch6;
Label l1,l2,l3,l4,l5;
TextField t1,t2,t3,t4;
Button b1,b2,b3;
Font ft;

f1 = new Frame("My Bank");

cg1 = new CheckboxGroup();
ch1 = new Checkbox("Short term[1yr]",cg1,false);
ch2 = new Checkbox("Medium term[2yrs]",cg1,false);
ch3 = new Checkbox("Long term[5yrs]",cg1,false);
ch4 = new Checkbox("Very long term[10yrs]",cg1,false);

l1 = new Label("Rate of Interest");
t1 = new TextField();
l2 = new Label("Deposit Amount");
t2 = new TextField();
l3 = new Label("Interest Amount");
t3 = new TextField();
l4 = new Label("Maturity Amount");
t4 = new TextField();

ch5 = new Checkbox("Senior Citizens");
ch6 = new Checkbox("NRI");

l5 = new Label("Extra : 0.5 Rate of Interest on Sr.Citizens and 1 Rate of Interest on NRI");

b1 = new Button("Calc");
b2 = new Button("Clear");
b3 = new Button("Exit");

f1.addWindowListener(new mywin());
ft=new Font("Arial",Font.ITALIC,20);
public class mywin extends WindowAdapter
public void windowClosing(WindowEvent we)
public void itemStateChanged(ItemEvent ie)
double r;

if(ch1.getState() == true)
else if(ch2.getState() == true)
else if(ch3.getState() == true)
else if(ch4.getState() == true)

if(ch5.getState() == true)
r = 0.5 + Double.parseDouble(t1.getText());

if(ch6.getState() == true)
r = 1 + Double.parseDouble(t1.getText());
}catch(Exception e){

public void actionPerformed(ActionEvent ae)
double ri,damt,in,mamt;
if(ae.getSource() == b1)
ri = Double.parseDouble(t1.getText());
damt = Double.parseDouble(t2.getText());

in = (damt * ri) / 100;
mamt = damt + in;

else if(ae.getSource() == b2)
else if(ae.getSource() == b3)
public static void main(String args[])
MyBank obj = new MyBank();

Nov 13, 2010 | Sun Java Programming Language (cdj-275)

1 Answer

What is J2ME?

Java Platform, Micro Edition (Java ME) provides a robust, flexible environment for applications running on mobile and other embedded devices—mobile phones, personal digital assistants (PDAs), TV set-top boxes, and printers. Java ME includes flexible user interfaces, robust security, built-in network protocols, and support for networked and offline applications that can be downloaded dynamically. Applications based on Java ME are portable across many devices, yet leverage each device's native capabilities.

Java Security
Java security technology includes a large set of APIs, tools, and implementations of commonly used security algorithms, mechanisms, and protocols. The Java security APIs span a wide range of areas, including cryptography, public key infrastructure, secure communication, authentication, and access control. Java security technology provides the developer with a comprehensive security framework for writing applications, and also provides the user or administrator with a set of tools to securely manage applications.

Jul 17, 2010 | Sun Java Studio Standard 5 (SSJI9501TL9M)...

1 Answer

How to convert infix to postfix using stacks in java programming?

u can try the follwing coding
import java.util.*;
//begin coding for the stack interface
interface Stack<E>
public boolean isEmpty();//tests is current stack is empty. Returns true if so, and false if not.
public E top() throws StackException;//retrieves value at the top of the stack. Stack cannot be empty.
public void push(E value) throws StackException;//pushes a value on the top of the stack.
public void pop() throws StackException;//removes a value from the top of the stack. Stack cannot be empty.
}//terminates coding of Stack interface

//begin coding for the objArrayStack class
class objArrayStack<E> implements Stack<E>
public objArrayStack()
}//terminates constructor
public void push(E value)throws StackException
if(topValue<ArraySize-1)//currrent stack is not full
}//terminates if
else //current stack is full
throw new StackException("Error: Overflow");
}//terminates push method
public void pop() throws StackException
if(!isEmpty())//current stack is not empty
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates pop method
public boolean isEmpty()
return topValue==-1;
}//terminates isEmpty method
public E top() throws StackException
if(!isEmpty())//stack is not empty
return (E)Info[topValue];
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates top method
//declare instance variables
final int ArraySize=10;
private Object Info[]=new Object[ArraySize];
private int topValue;

//begins coding for the StackException class
class StackException extends RuntimeException
public StackException(String str)
}//terminates text of constructor
}//terminates text of StackException class

//method to convert from infix to postfix notation
public static String InToPost(String infixString)
//operator stack initialized
objArrayStack<Character> operatorStack = new objArrayStack<Character>();
//postfix string initialized as empty
String postfixString = " ";
//scan infix string and take appropriate action
for(int index = 0; index < infixString.length(); ++index)
char chValue = infixString.charAt(index);
if(chValue == '(')
else if(chValue == ')')
Character oper =;
while(!(oper.equals('(')) && !(operatorStack.isEmpty()))
postfixString += oper.charValue();
oper =;
}//end while loop
}//end else if
else if(chValue == '+' || chValue == '-')
if(operatorStack.isEmpty()) //operatorStack is empty
else //current operatorStack is not empty
Character oper =;
while(!(operatorStack.isEmpty() || oper.equals(new Character('(')) || oper.equals(new Character(')'))))
postfixString += oper.charValue();
}//ends while loop
}//end else
}//end else if
else if(chValue == '*' || chValue == '/')
Character oper =;
while(!oper.equals(new Character('+')) && !oper.equals(new Character('-')) && !operatorStack.isEmpty())
postfixString += oper.charValue();
}//end while loop
}//end else
}//end else if
postfixString += chValue;
}//end for loop
Character oper =;
if(!oper.equals(new Character('(')))
postfixString += oper.charValue();
}//end if
}//end while
return postfixString ;
}//terminates text of InToPost method

public static void main(String[]args)
objArrayStack mystack = new objArrayStack();
System.out.println("Enter a string");
Scanner scan = new Scanner(;
String str = scan.nextLine();
}//terminates text of main method
}//terminates text of objArrayStack class

Mar 16, 2010 | Sun Java Programming Language (cdj-275)

1 Answer

Sir, give me sample java problem! for i can solve.

Look at the method below which finds prime numbers. public class Primes { private static void findPrimes(int nValues, boolean printPrimes) { boolean isPrime = true; for (int i = 2; i <= nValues; i++) { isPrime = true; for (int j = 2; j < i; j++) { if (i % j == 0) { isPrime = false; break; } } if (printPrimes && isPrime) { System.out.println(i); } } } // REMAINING METHODS NOT SHOWN }Implement the method findPrimesFaster in class Primes by copying the code from the findPrimes method and modifying it to have the following features:
  • Uses labeled continue instead of break.
  • Does not require the isPrime variable.
  • Only tries to divide by integers up to the square root of the number being tested.

Sep 25, 2009 | Sun Java Programming Language (cdj-275)

1 Answer

I want to read text file which is located in c drive using java code can anybody help me out

import java.util.Scanner;

public final class ReadWithScanner { public static void main(String... aArgs) throws FileNotFoundException {
ReadWithScanner parser = new ReadWithScanner("C:\\Temp\\test.txt");

* @param aFileName full name of an existing, readable file.

public ReadWithScanner(String aFileName){
fFile = new File(aFileName);

/** Template method that calls {@link #processLine(String)}. */
public final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(fFile);
try {
//first use a Scanner to get each line
while ( scanner.hasNextLine() ){
processLine( scanner.nextLine() );
finally {
//ensure the underlying stream is always closed

* Overridable method for processing lines in different ways.
* <P>This simple default implementation expects simple name-value pairs, separated by an
* '=' sign. Examples of valid input :
* <tt>height = 167cm</tt>
* <tt>mass = 65kg</tt>
* <tt>disposition = "grumpy"</tt>
* <tt>this is the name = this is the value</tt>

protected void processLine(String aLine){
//use a second Scanner to parse the content of each line
Scanner scanner = new Scanner(aLine);
if ( scanner.hasNext() ){
String name =;
String value =;
log("Name is : " + quote(name.trim()) + ", and Value is : " + quote(value.trim()) );
else {
log("Empty or invalid line. Unable to process.");
//(no need for finally here, since String is source)

private final File fFile;

private static void log(Object aObject){

private String quote(String aText){
String QUOTE = "'";
return QUOTE + aText + QUOTE;

Jun 22, 2009 | Sun Java Programming Language (cdj-275)

1 Answer

Code for method parseInt() in java

parseInt(java.lang.String, int)

This code takes two arguments, a string constructor from the Java language and an integer. Its purpose is to parse (meaning de-construct or disassemble into component parts) one data type into another.

Here is an example of a Java program to specify and print out the dimensions of a rectangle, taken from the page

class Rectangle{
int length, breadth;
void show(int x, int y){
length = x;
breadth = y;
int calculate(){
return(length * breadth);
public class EnterValuesFromKeyboard{
public static void main(String[] args) {
Rectangle rectangle = new Rectangle();
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);, b);
System.out.println(" you have entered these values : " + a + " and " + b);
int area = rectangle.calculate();
System.out.println(" area of a rectange is : " + area);

Apr 09, 2009 | Sun Java Programming Language (cdj-275)

1 Answer

Hi everybody can anyone help me with the project ''Data Hiding in Audio Files'' project in Java and how to run the project with full source code to

The Circle Class Using Data Hiding and Encapsulation package shapes; // Specify a package for the class public class Circle { // The class is still public // This is a generally useful constant, so we keep it public public static final double PI = 3.14159; protected double r; // Radius is hidden, but visible to subclasses // A method to enforce the restriction on the radius // This is an implementation detail that may be of interest to subclasses protected checkRadius(double radius) { if (radius < 0.0) throw new IllegalArgumentException("radius may not be negative."); } // The constructor method public Circle(double r) { checkRadius(r); this.r = r; } // Public data accessor methods public double getRadius() { return r; }; public void setRadius(double r) { checkRadius(r); this.r = r; } // Methods to operate on the instance field public double area() { return PI * r * r; } public double circumference() { return 2 * PI * r; } }

Mar 25, 2009 | Compilers & Programming Tools

1 Answer


A simple RSA implementation I wrote in an hour couple years ago :). Comments are in polish but all identifiers are in english. The code is fairly simple so it should be self explanatory. Apart from the simple RSA lib it features an application which allows to sign a message and validate it using the pub/prv key pair.

Jan 22, 2009 | ArcMedia JavaScript Source Code 3000 Pro...

1 Answer

Data mining

Hello, you can find the best open-source implementation of data-mining algorithms here:

You can use the built-in application or embed it in your own code.
Of course it implements several naive bayes algorithms

Mar 20, 2008 | Compilers & Programming Tools

Not finding what you are looking for?
Borland Turbo C++ Suite 1.0 (TCB0000WWFS180) for PC Logo

Related Topics:

1,195 people viewed this question

Ask a Question

Usually answered in minutes!

Top Borland Compilers & Programming Tools Experts

Yoav Shilon
Yoav Shilon

Level 2 Expert

101 Answers


Level 3 Expert

2598 Answers


Level 3 Expert

733 Answers

Are you a Borland Compiler and Programming Tool Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides