Pythagorean Triples

JAVA

    Sponsored Links

    Next

  • 1. Linked List Help
    hey guys, I am writing a program which will use a LinkedList array. I declared the array n stuff and now i want to add an object at the specified index. I did the following code to add. It gives me an error that add method cannot be found. I am really confused here. Can someone please help me here. Thank you so much :) adjacentCities.add(position,new String(originCity)) here position is an int and originCity is a string.
  • 2. java set path problem in linux
    I just installed Java 5 on red hat linux 9. The location is /usr/java/jdk1.5.0_05 I then updated .bash_profile in /home/joe and added the following export PATH=/usr/java/jdk1.5.0_05/bin:$PATH I opened a new shell and typed java -version, but still has error saying command not found. any ideas? Please advise. thanks!!
  • 3. compiling for either of two SDK versions..
    I recently upgraded to 1.5 (though sometimes wish I hadn't..) but am now working on a project that has to run on 1.4 (I mean be ABLE to run on 1.4, since am assuming, since it has been stated here and elsewhere, that most uers are not on JRE 1.5 yet.. this is for an applet..) I'd like to know can I compile for 1.4 by passing version to compiler or something, do I have to have both versions of sdk/jre installed for this.. (and then do how you set path for both javacs, then choose which one to use, etc..) thank you.. Frances
  • 4. [OT] Artificial Intelligence
    Aki Laukkanen wrote: > Oliver Wong wrote: >> The years after that, fleet designs based around the idea of >> multiple weaker ships became very popular. > > <okay, going a bit off topic here> > This was, by the way, extremely annoying in the game "Master of Orion". > If one of the computer players was controlling the Klackon race (really > fast builders), they would create an armada of about 20.000 tiny ships > armed with the basic laser cannon in the time it took the human player > to create a dozen large battlesips with top-of-high-tech weapons. > They would then decimate the human player's fleet with sheer numbers. > </offtopic> > > Another example of unexpectedly cunning AI strategy. You say "unexpectedly". Was this not a deliberate feature added by the game designers? Or was it emergent behavior they didn't expect?

Pythagorean Triples

Postby ILackJavaSkillz » Sun, 07 Nov 2004 04:10:27 GMT

My professor isn't great at explaining assignments and is going too fast.
How do I create a java program that will print pythagorean triples of a
number I have to type in. 

For example... I need to print: "Enter an integer" 
If I enter 10, I need it to print the pythagorean triples. It should print
(3,4,5) and (6,8,10) since those 2 are the pythagorean triples.


Re: Pythagorean Triples

Postby Eric Sosman » Sun, 07 Nov 2004 04:43:08 GMT



    You are not very good at explaining assignments, either.
What has the "10" got to do with anything?  And why are you
supposed to print only two Pythagorean triples, when there
is an infinite supply?  It could even be argued that the "two"
triples you have shown are really the same; are you supposed
to include trivial magnifications as well as the "canonical"
triples?

    The ability to formulate a clear problem description is
indispensable in the practice of programming.  If you lack
that ability and cannot develop it, perhaps you should seek
another line of endeavor.

-- 
 XXXX@XXXXX.COM 


Re: Pythagorean Triples

Postby Fuddzy » Sun, 07 Nov 2004 07:17:21 GMT






Eric............ you provided that kid with a great answer,  free 
student counseling  and a kick-start toward his own self-awareness.
Great work Man


Re: Pythagorean Triples

Postby KS » Mon, 08 Nov 2004 01:56:37 GMT



I take it you mean in a xterm?


Again, do you mean in a shell window?

What are pythagorean triples again?

........been ages since I did maths.

Re: Pythagorean Triples

Postby Alex Hunsley » Sat, 13 Nov 2004 01:50:41 GMT



If it's not even clear what the assignment is, why are you here? Why 
aren't you chasing up your professor to actually find out what the 
problem is? Your problem description is too vague; you're wasting our time.

If instead you meant "I'm not great at java", then get started! Work 
from hello world onwards.



Similar Threads:

1.Triple DES Bad Data Error Please Help!!!!

I'm working on decypting Java encrypted text using TripleDES in VB.NET.

Below is
the algorithm submitted by the producer of the ciher text:

Things needed for the consumer (vendor)


1) String used to generate the key and also the algorithm used to
generate the key
   Algorithm for generating the key -- Take a string which you choose
to be secure
   (known to you and the recieving party), do a MD5 of the string and
take the
   first 24 charactrers of this as the KEY


2) Post Parameter field name used to carry the SAML assertion -
SAMLPost


3) IV used in the TripleDES algortithm - currently IV is 00000000


The issue I'm having is that when i use PKCS7 padding, i get a Bad Data



exception. I have to use this padding because the producer used PKCS5
in Java. Below is the decryption code provided by the producer:
package org.security.assertion;


import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import sun.misc.BASE64Decoder;
import sun.misc.CharacterEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.math.BigInteger;


/*
 * Used for Decrypting of the String
 * with Triple DES algorithm of : DESede/ECB/PKCS5Padding
 */


public class DataDecryption implements Serializable {


        /**
          * Generate a DESede SecretKey object
          *
         **/


        //private static String l_strEncodedKey =
"dGhpcyBpcyBhIDI0IGJ5dGUga2V5ICEh";


private static String l_strEncodedKey = "!38lrakm^&pniku#@34557@@ge!";


        private SecretKey getSecretKey()


        {
             SecretKey l_objSecretKey = null;
             byte[] l_byteSecretKey = null;
             DESedeKeySpec l_objDESedeKeySpec = null;
             SecretKeyFactory l_objKeyFactory = null;
             String l_strHpassword = "";
             BigInteger l_bintBigInteger;
            try{


                      try{


                                MessageDigest l_msgdgstMD =
MessageDigest.getInstance(
"MD5" );
                                l_msgdgstMD.update(
l_strEncodedKey.getBytes() );


System.out.println(l_strEncodedKey.getBytes().toString());
                                l_bintBigInteger = new BigInteger( 1,
l_msgdgstMD.digest()
);
                                System.out.println("Key is :" +
l_bintBigInteger.toString());
                                l_strHpassword =
l_bintBigInteger.toString( 16  );
                                System.out.println("Key is :" +
l_strHpassword.toString());
                                l_strHpassword =
l_strHpassword.substring(0,24);
                                System.out.println("Key is :" +
l_strHpassword);


                      }catch ( NoSuchAlgorithmException ns ){


                                System.out.println("An Error Occured in

hashcoding the
password : " + ns);


                       }


                    try{


                        l_byteSecretKey = l_strHpassword.getBytes();
                        System.out.println(l_byteSecretKey);


                     }catch (Exception Ex){


                        System.out.println("An Error Occured while
getting Byte
Secret Key : " + Ex);


                     }


                      try{


                        // Create a DESede key spec from the key
                           l_objDESedeKeySpec = new
DESedeKeySpec(l_byteSecretKey);


                        }catch (java.security.InvalidKeyException Ex){


                                System.out.println("The Key is not
Valid  : " + Ex);


                        }


                      try{


                        // Get the secret key factor for generating
DESede keys
                           l_objKeyFactory =
SecretKeyFactory.getInstance("DESede");


                        }catch (java.security.NoSuchAlgorithmException
Ex){


                                System.out.println("Invalid Algorithm
: " + Ex);


                        }


                        try{


                        // Generate a DESede SecretKey object
                           l_objSecretKey =
l_objKeyFactory.generateSecret(l_objDESedeKeySpec);


                        }catch
(java.security.spec.InvalidKeySpecException Ex){


                                System.out.println("Invalid Key Spec  :

" + Ex);


                        }


              }catch (Exception e){


                        System.out.println("An error occured in
getSecretKey method :
" + e);


              }


                return l_objSecretKey;


        }


        public String getDecryptedData(String p_CipherText) {


                String l_strEncryptedData = "";
                Cipher l_objCipher = null;
                byte[] l_byteEncryptedData = null;


                try{


                        try{
                                // Create a DESede Cipher
                                l_objCipher =
Cipher.getInstance("DESede/ECB/PKCS5Padding");


                        }catch (javax.crypto.NoSuchPaddingException
Ex){


                                System.out.println("Invalid Padding :
" + Ex);


                        }


                        try{
                                // Initialize the cipher and put it
into decrypt mode
                                l_objCipher.init(Cipher.DECRYPT_MODE,
getSecretKey());


                        }catch (java.security.InvalidKeyException Ex){


                                System.out.println("Invalid Key :  " +
Ex);


                        }


                        try{


                        // Decrypt the data
                        System.out.println(new
BASE64Decoder().decodeBuffer(p_CipherText));
                           l_byteEncryptedData =
l_objCipher.doFinal((new
BASE64Decoder()).decodeBuffer(p_CipherText));


                        }catch (java.io.IOException ExIO){


                                System.out.println("An error while
Decoding :  " + ExIO);


                        }catch (javax.crypto.BadPaddingException
Exbadpadding){


                                System.out.println("Bad Padding :  " +
Exbadpadding);


                        }


                        // Byte to String Conversion
                        l_strEncryptedData = new
String(l_byteEncryptedData);


                  }catch (Exception e){


                        System.out.println("An error occured in
getEncryptedData method :
" + e);


                  }
                   return l_strEncryptedData;


        }



}


Using this code, i successfully decrypted the cipher text. Here's my
vb.net code:

    Public Function Decrypt(ByVal cipherString As String, ByVal
useHashing As Boolean) As String
        Dim keyArray As Byte()
        'get the byte code of the string


        Dim toEncryptArray As Byte() =
Convert.FromBase64String(cipherString)


        Dim key As String = "!38lrakm^&pniku#@34557@@ge!";


        If useHashing Then
            'if hashing was used get the hash code with regards to your



key
            Dim hashmd5 As MD5CryptoServiceProvider = New
MD5CryptoServiceProvider
            keyArray =
hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key))
            'Dim str As String = Me.GetAsString(keyArray).Substring(0,
24)
            'keyArray = utf8.GetBytes(str)
            Dim j As Integer
            Dim i As String
            For j = 0 To keyArray.Length - 1
                i = i + Hex(keyArray(j))
            Next
            'Dim i As Int64 = BitConverter.ToInt64(keyArray, 0)


            Dim str As String = i.Substring(0, 24)


            Dim keyArr(23) As Byte
            For j = 0 To str.Length - 1
                keyArr(j) = Byte.Parse(str.Chars(j),
System.Globalization.NumberStyles.AllowHexSpecifier)
                'If Char.IsLetter(str.Chars(j)) Then
                'keyArr(j) = byte.Parse(
                'Else
                'keyArr(j) =
CByte(Microsoft.VisualBasic.Val(str.Chars(j)))
                ' End If
            Next
            keyArray = Nothing
            keyArray = keyArr


            'release any resource held by the MD5CryptoServiceProvider


            hashmd5.Clear()
        Else
            'if hashing was not implemented get the byte code of the
key
            keyArray = ASCIIEncoding.ASCII.GetBytes(key)
        End If


        Dim tdes As TripleDESCryptoServiceProvider = New
TripleDESCryptoServiceProvider


        Dim f As Array = tdes.LegalKeySizes


        'set the secret key for the tripleDES algorithm
        tdes.Key = keyArray
        'mode of operation. there are other 4 modes. We choose
ECB(Electronic code Book)


        tdes.Mode = CipherMode.ECB
        'padding mode(if any extra byte added)
        tdes.Padding = PaddingMode.PKCS7
        Dim d As Array = tdes.LegalBlockSizes()


        tdes.IV = New Byte() {0, 0, 0, 0, 0, 0, 0, 0}


        Dim cTransform As ICryptoTransform = tdes.CreateDecryptor()
        Dim resultArray As Byte() =
cTransform.TransformFinalBlock(toEncryptArray, 0,
toEncryptArray.Length)
        'Release resources held by TripleDes Encryptor
        tdes.Clear()
        'return the Clear decrypted TEXT
        Return UTF8Encoding.UTF8.GetString(resultArray)
        'Return Convert.ToBase64String(resultArray)
    End Function


Any help will be greatly appriciated. Im facing a deadline shortly, so
please help me. thanks in advance.

2.Triple DES Perl to Java

3.Triples?

    Where can I find simple code of triples.


4.Triple DES Perl to Java

5.triple quintzee

6. mcrypt, triple des and java.

7. This stock is showing triple-digit earnings growth this year ol hvcauizb



Return to JAVA

 

Who is online

Users browsing this forum: No registered users and 86 guest