Implement RSA algorithm

Hello, everyone,
For some reason, I have to write a program to implement RSA algorithm by myself, instead of get RSA from some provider. In RFC3447(PKCS#1), there is a step during the RSA encryption, which is called 'EME-OAEP encoding'. Actually, the main purpose of this 'EME-OAEP encoding' is to do the 'padding' thing for plaintext.
I am just wondering, is there any class or method in java which can do the 'EME-OAEP encoding'? (I just don't want to implement the whole 'EME-OAEP encoding' process by myself)
Thank you for any help
Regards

I don't think any of the crypto pieces are available
"standalone" - they're all internal to the Cipher
impls.
GrantHi, I found this link:
http://www.informatik.tu-darmstadt.de/TI/Forschung/FlexiProvider/docs/flexiprovider/docs/de/flexiprovider/core/rsa/PKCS1Operations.html
I will take a look at this link later, don't know if it works or not.

Similar Messages

  • Implementing RSA algorithm

    Dear All,
    I want to implement RSA algorithm by using java.tell me whether we can implement RSA by using JCE or any different functionalities is there. i want some soft copy related to RSA pls help me out.

    Hello,
    I do not know how much do you know about implementing algorithms and what are you exactly watching for.
    Some days ago I find this information about (I can not remind where did I take it, maybe was from this forum) for install JCE and BouncyCastle software for encryption.
    You should first download change the policy of the JCE By downloading this
    http://java.sun.com/j2se/1.4.2/download.html just JCE a and unzip in a folder read the read me doc so you should cut that 2 file and put here C:\j2sdk1.4.2_02\jre\lib\security
    and here C:\Program Files\Java\j2re1.4.2_02\lib\security
    done this then download the bouncy jar file from http://www.bouncycastle.org/latest_releases.html take the bcprov-jdk14-120.jar and put in following directories
    C:\j2sdk1.4.2_02\jre\lib\ext
    C:\Program Files\Java\j2re1.4.2_02\lib\ext
    then you need to change the environment variable so in the following directories open "java.security" in both
    C:\j2sdk1.4.2_02\jre\lib\security
    C:\Program Files\Java\j2re1.4.2_02\lib\security
    and edit it and add the extra line
    security.provider.numberProvider=org.bouncycastle.jce.provider.BouncyCastleProvider
    Then you should test if everything is good installed:
    import java.security.Provider;
    import java.security.Security;
    import java.util.Set;
    import java.util.Iterator;
    public class Verifica {
         public static void main(String[] args) {
              Provider[] providers = Security.getProviders();
              for (int i = 0; i < providers.length; i++) {
                   Provider provider = providers;
                   System.out.println("Provider name: " + provider.getName());
                   System.out.println("Provider information: " + provider.getInfo());
                   System.out.println("Provider version: " + provider.getVersion());
                   Set entries = provider.entrySet();
                   Iterator iterator = entries.iterator();
                   /*while (iterator.hasNext()) {
                        System.out.println("Property entry: " + iterator.next());
    And you will see if there is RSA. (It should)
    An example:
    Encription:
    //Object Cipher to encript data.
    Cipher encriptDatos = Cipher.getInstance("RSA", "BC");
    encriptDatos.init(Cipher.ENCRYPT_MODE, servidorPub); //servidorPub is the server public key you should have or generate
    //data encryption
    byte[] datosEncriptados = encriptDatos.doFinal(b);
    Desencryption:
    Cipher Cipherdesencriptacion = Cipher.getInstance("RSA", "BC");
    Cipherdesencriptacion.init(Cipher.DECRYPT_MODE, servidorPriv); //ServidorPriv is the server public key
    //data desencryption
    byte[] datosClaros = Cipherdesencriptacion.doFinal(datos); //datos = encripted data.I am sure you can find many examples of encrypt and decrypt. But hope this help as introduction.
    - Susana

  • Compability problem with Java and Python  RSA algorithm implementation

    I have client server application. Server is writtein in python, client in java. Client receives messages from server encrypted with RSA (http://stuvel.eu/rsa), and I'm unable to decrypt it. It seems that this is RSA algorithm compatibility problem. I'm using algorithm from java.security package, instatinating Cipher object like this: c = Cipher.getInstance("RSA"); . I noticed that this algorithm produces for input blocks of lengtrh <=117 ouput block of length 128. Server I guess uses the most triviall impelentation of RSA ( (1 byte is encrypted to 1 byte) So i want to make my java algorithm compatibile with this one which server uses. How to do that ? Do i have to instatinate Cipher object in different way ? Or use another library ?

    azedor wrote:
    First you said it was no good because it could only handle <= 117 byte inputs, now you say it is no good because it produces a 128-byte output. You're not making sense.First i said that this two RSA implementations are not compatibile, and first reason i noticed firstly is that Python imlementation for input of length N produces cryptogram of the same length. Not true. In general, the RSA encryption of any number of bytes less than the length of the modulus will produce a result of length near that of the modulus. When N is less than the length of the modulus, it is rare that N bytes of cleartext produces N bytes of ciphertext.
    Java implementation for data block of length <=117 produces alwasy 128 bytes of output.Pretty much correct and very much desirable. This is primarily a function of the PKCS1 padding which is used to solve two basic problems. First, as I alluded to in my first response, it is the nature of the algorithm that leading zeros are not preserved and second when the cleartext is very small (a few bytes) the exponentiation does not roll over and it is easy to decrypt the result. Both these problems are addressed by PKCS1 padding.
    >
    >
    After what sabre150 said i think of giving up idea of translating Python code to Java and considering to use another assymetric cryptography algorithms on both sides. Can you recommend me sth what should be compatibile with Python ?This seems to be at odds with your statement in reply #3 "Also have acces only to client code so i have to change sth in java." ! This statement is why I said "I suspect ... you have dug a deep hole".
    In your position I would use the Python bindings for openssl. Once more, Google is your friend.

  • My RSA Algorithm

    Hi there, hope someone can help me out alittle here.
    I pretty new to encryption, but I'm trying to code my own RSA algorithm in java, and have a few questions about it.
    *I want the encryption level to be 1024bit, so I should aim to get 2 primes at 512bit ?
    *What bit-level of 'e' (relative prime to phi_n) should I aim for? If I aim for a 1024bit 'e', will this increase security ?
    *I have got a java version of the MersenneTwister psuedorandom number generator, as I thought it would be better than the standard java version (new Random()), is it 'safe' to even use this to calculate the 2 random primes and 1 random 'e' using the BigInteger constructor as so :
    new BigInteger(bit-size, primecertainty, new MersenneTwister())
    or do I need to come up with another way of randomly generating these 3 values ? ie:is any random number generator not suitable for secure encryption?
    I was thinking about having a JFrame, and telling the user to move the mouse around while grabbing the mouse coordinates at certain intervals, and using these values in some way to generate the values.
    Thanks for any help you can give me

    I'm a bit of a noob when it comes to this so please correct anything I'm saying wrong.
    To my limited understanding, RSA is a way of cryptography using the public/private (assymetric) key system. I'm just trying to implement it myself. The reason I'm doing this is two-fold.
    Firstly, to my understanding java implementations of encryption are limited to 256bit (is this correct?), I don't want to be restricted to this limit.
    Secondly, this is mainly for self education purposes as I did a short short course of cryptography in general and they teach you the basics of loads of things, and so gain a decent understanding of none.
    Is there a algorithm written in java already out there, that is proven to be "air-tight"?, as you are correct designing my own probably would have weaknesses and as I'm not a mathematician checking it for vulnerabilities wouldn't be ideal for me.
    I basically am looking for a good way to generate 2 large primes, and then randomly generate 'e'.
    At first, my 'e' was the first value it found, incrementing up from 2 until it found one. I'm currently trying to get a reliable method of a randomly generated 'e'.
    Any help in these areas would be appreciated.

  • Help required in implementing the algorithm

    Actually I am brand new to the java programming, and i need some help to implement the algorithm below in java.
    I have the dataset required for the execution,
    Can any body please help me?
    Input: (1) a source database D,
    (2) a min support,
    (3) a min confidence,
    (4) a set of recommended items Y
    Output: a transformed database D, where rules containing
    Y on RHS will be hidden
    1. Find large 1-item sets from D;
    2. For each hidden item y �� Y
    3. If y is not a large 1-itemset, then Y := Y &#8722; {y};
    4. If Y is empty, then EXIT;// no AR contains Y in RHS
    5. Find large 2-itemsets containing items in Y from D;
    6. For each y �� Y {
    7. For each large 2-itemset containing y {
    8. Compute confidence of rule U, where U is a rule likex �� y;
    9. If confidence(U) �� min conf, then { //Calculate # of transactions required to lower the confidence of U
    10. Calculate iterNumConf = _|D|&#8727;(supp(xy) &#8722; minconf &#8727;supp(x))_;
    //Calculate # of transactions required to lower the support of U
    11. Calcualte iterNumSupp = _|D|&#8727;(supp(xy)&#8722; min supp)_;
    12. Calculate k = minimum (iterNumConf, iterNumSupp);
    13. Calculate |TR| = |xy|; //|TR|: # of transactions inTR
    14. if k > |TR|
    15. Can not hide U;
    16. else {
    17. Find T kR = first k transactions that contain xy;
    18. Sort T kR in ascending order by the number of items;
    19. for i = 1 to iterNum do { 20. Choose the first transaction t from T kR ;
    21. Modify t so that y is not supported, the RHS(U);
    22. |xy| = |xy| &#8722; 1; // update support count of xy
    23. confidence(U) = |xy|/|x|; // update confidence
    24. Remove and save the first transaction t from T kR ;
    25. }; // end for iterNum
    26. }; // end if confidence(U)
    27. }; // end of each large 2-itemset
    28. Remove y from Y;
    29. } // end of for each y
    30. Output updated D, as the transformed D;

    The way you post that, it looks very much like "Do my work for me". Nobody around here likes that kind of post, they consider it lazy and selfish. But perhaps you didn't mean it that way? Why don't you explain what you have done and what parts of it you are having problems with. Explain those problems in detail.

  • How to implement hasing algorithm in oracle

    implement hasing algorithm in oracle

    Assuming you're using the enterprise edition of the database and that you've licensed the partitioning option, you specify the number of hash partitions you want when you create the table. The SQL Reference for the CREATE TABLE statement has the following example
    CREATE TABLE hash_products
        ( product_id          NUMBER(6)
        , product_name        VARCHAR2(50)
        , product_description VARCHAR2(2000)
        , category_id         NUMBER(2)
        , weight_class        NUMBER(1)
        , warranty_period     INTERVAL YEAR TO MONTH
        , supplier_id         NUMBER(6)
        , product_status      VARCHAR2(20)
        , list_price          NUMBER(8,2)
        , min_price           NUMBER(8,2)
        , catalog_url         VARCHAR2(50)
        , CONSTRAINT          product_status_lov_demo
                              CHECK (product_status in ('orderable'
                                                      ,'planned'
                                                      ,'under development'
                                                      ,'obsolete')
    PARTITION BY HASH (product_id)
    PARTITIONS 5
    STORE IN (tbs_01, tbs_02, tbs_03, tbs_04); You'd just specify 4 or 8 partitions, your partition key, etc.
    It doesn't make sense, however, to try to join two hash-partitioned tables on the hash key value. What is it, exactly, that you're trying to accomplish.
    Justin

  • Implementing own algorithms in  SignatureMethod for XML Digital Signature

    Is it possible to implement own algorithms in SignatureMethod (other than DSA_SHA1, RSA_SHA1 and HMAC_SHA1)?
    Thanks.

    I believe the problem is that you are not explicitly adding the xades namespace
    attribute to the SignedProperties element before generating the signature. Thus,
    the namespace attribute is not visible when canonicalizing, but when you serialize the
    DOM tree to an output stream, (for reasons I'm not entirely sure why), the namespace
    attribute is visible and is added to the SignedProperties element, which breaks the
    signature.
    You must always explicitly add namespace attributes using the Element.setAttributeNS
    method. Try changing the following code from:
    Element SPElement = createElement(doc, "SignedProperties", null,xadesNS);
    to:
    Element SPElement = createElement(doc, "SignedProperties", null,xadesNS);
    SPElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", xadesNS);

  • Who an give me the java file implements LZRW  Algorithms

    pray for the java file implements LZRW Algorithms,very thanks.

    thank you all very much.
    i just use it in java, so i want change it all in pure java.
    but the Algorithms is so complex, i give up after some times.
    so i have to use jni , this is my file, it can work. but is not pure java, a pity!
    #include <stdio.h>
    #include <jni.h>
    #include "my_Tool.h"
    /* Begin of LZRW_1.C */
    #ifndef TURE
         #define BTRUE 1
    #endif
    #define UBYTE unsigned char /* Unsigned byte (1 byte ) */
    #define UWORD unsigned int /* Unsigned word (2 bytes) */
    #define ULONG unsigned long /* Unsigned longword (4 bytes) */
    #define FLAG_BYTES 4 /* Number of bytes used by copy flag. */
    #define FLAG_COMPRESS 0 /* Signals that compression occurred. */
    #define FLAG_COPY 1 /* Signals that a copyover occurred. */
    void fast_copy(p_src,p_dst,len) /* Fast copy routine. */
    UBYTE p_src,p_dst; {while (len--) *p_dst++=*p_src++;}
    void compress_LZRW_1(p_src_first,src_len,p_dst_first,p_dst_len)
    /* Input : Specify input block using p_src_first and src_len. */
    /* Input : Point p_dst_first to the start of the output zone (OZ). */
    /* Input : Point p_dst_len to a ULONG to receive the output length. */
    /* Input : Input block and output zone must not overlap. */
    /* Output : Length of output block written to p_dst_len.               /
    /* Output : Output block in Mem[p_dst_first..p_dst_first+*p_dst_len-1]. */
    /* Output : May write in OZ=Mem[p_dst_first..p_dst_first+src_len+256-1].*/
    /* Output : Upon completion guaranteed p_dst_len<=src_len+FLAG_BYTES.  /
    UBYTE p_src_first,p_dst_first; ULONG src_len,*p_dst_len;
    #define PS p++!=s++ /* Body of inner unrolled matching loop. */
    #define ITEMMAX 16 /* Maximum number of bytes in an expanded item. */
    {UBYTE *p_src=p_src_first,*p_dst=p_dst_first;
    UBYTE *p_src_post=p_src_first+src_len,*p_dst_post=p_dst_first+src_len;
    UBYTE *p_src_max1=p_src_post-ITEMMAX,*p_src_max16=p_src_post-16*ITEMMAX;
    UBYTE *hash[4096],*p_control; UWORD control=0,control_bits=0;
    *p_dst=FLAG_COMPRESS; p_dst+=FLAG_BYTES; p_control=p_dst; p_dst+=2;
    while (BTRUE)
    {UBYTE *p,*s; UWORD unroll=16,len,index; ULONG offset;
        if (p_dst>p_dst_post) goto overrun;
        if (p_src>p_src_max16)
          {unroll=1;
           if (p_src>p_src_max1)
             {if (p_src==p_src_post) break; goto literal;}}
    begin_unrolled_loop:
    index=((40543*((((p_src[0]<<4)^p_src[1])<<4)^p_src[2]))>>4) & 0xFFF;
    p=hash[index]; hash[index]=s=p_src; offset=s-p;
    if (offset>4095 || p<p_src_first || offset==0 || PS || PS || PS)
    {literal: *p_dst++=*p_src++; control>>=1; control_bits++;}
    else
    {PS || PS || PS || PS || PS || PS || PS ||
              PS || PS || PS || PS || PS || PS || s++; len=s-p_src-1;
              *p_dst++=((offset&0xF00)>>4)+(len-1); *p_dst++=offset&0xFF;
              p_src+=len; control=(control>>1)|0x8000; control_bits++;}
    end_unrolled_loop: if (--unroll) goto begin_unrolled_loop;
    if (control_bits==16)
    {*p_control=control&0xFF; *(p_control+1)=control>>8;
    p_control=p_dst; p_dst+=2; control=control_bits=0;}
    control>>=16-control_bits;
    p_control++=control&0xFF; p_control++=control>>8;
    if (p_control==p_dst) p_dst-=2;
    *p_dst_len=p_dst-p_dst_first;
    return;
    overrun: fast_copy(p_src_first,p_dst_first+FLAG_BYTES,src_len);
    p_dst_first=FLAG_COPY; p_dst_len=src_len+FLAG_BYTES;
    void decompress_LZRW_1(p_src_first,src_len,p_dst_first,p_dst_len)
    /* Input : Specify input block using p_src_first and src_len. */
    /* Input : Point p_dst_first to the start of the output zone. */
    /* Input : Point p_dst_len to a ULONG to receive the output length. */
    /* Input : Input block and output zone must not overlap. User knows */
    /* Input : upperbound on output block length from earlier compression. */
    /* Input : In any case, maximum expansion possible is eight times. */
    /* Output : Length of output block written to p_dst_len.               /
    /* Output : Output block in Mem[p_dst_first..p_dst_first+*p_dst_len-1]. */
    /* Output : Writes only in Mem[p_dst_first..p_dst_first+*p_dst_len-1]. */
    UBYTE p_src_first, p_dst_first; ULONG src_len, *p_dst_len;
    {UWORD controlbits=0, control;
    UBYTE *p_src=p_src_first+FLAG_BYTES, *p_dst=p_dst_first,
           *p_src_post=p_src_first+src_len;
    if (*p_src_first==FLAG_COPY)
       {fast_copy(p_src_first+FLAG_BYTES,p_dst_first,src_len-FLAG_BYTES);
        *p_dst_len=src_len-FLAG_BYTES; return;}
    while (p_src!=p_src_post)
    {if (controlbits==0)
          {control=*p_src++; control|=(*p_src++)<<8; controlbits=16;}
    if (control&1)
    {UWORD offset,len; UBYTE *p;
           offset=(*p_src&0xF0)<<4; len=1+(*p_src++&0xF);
           offset+=*p_src++&0xFF; p=p_dst-offset;
           while (len--) *p_dst++=*p++;}
    else
    p_dst++=p_src++;
    control>>=1; controlbits--;
    *p_dst_len=p_dst-p_dst_first;
    JNIEXPORT jbyteArray JNICALL Java_my_Tool_compress
    (JNIEnv * env, jclass cls, jbyteArray src) {
         jsize srcLen ;
         jbyte* ba;
         int zipLen;
         char zipBuf[4096];
         jbyteArray ret ;
         srcLen = (*env)->GetArrayLength(env,src);
         printf("the length is %d \n", srcLen);
         ba = (*env)->GetByteArrayElements(env,src,JNI_FALSE);
         compress__LZRW_1(ba,srcLen,zipBuf,&zipLen);
         printf("ret len is : %d", zipLen);
         ret = (*env)->NewByteArray(env,zipLen);
         (*env)->SetByteArrayRegion(env,ret,0,zipLen,(jbyte*)zipBuf);
         return ret;
    JNIEXPORT jbyteArray JNICALL Java_my_Tool_uncompress
    (JNIEnv * env, jclass cls, jbyteArray src) {
         jsize srcLen ;
         jbyte* ba;
         int unzipLen;
         char unzipBuf[4096];
         jbyteArray ret ;
         srcLen = (*env)->GetArrayLength(env,src);
         printf("the length is %d \n", srcLen);
         ba = (*env)->GetByteArrayElements(env,src,JNI_FALSE);
         decompress__LZRW_1(ba,srcLen,unzipBuf,&unzipLen);
         printf("ret len is : %d\n", unzipLen);
         ret = (*env)->NewByteArray(env,unzipLen);
         (*env)->SetByteArrayRegion(env,ret,0,unzipLen,(jbyte*)unzipBuf);
         return ret;
    }

  • RSA Algorithm

    Whether it is possible to encrypt a String Message using RSA Algorithm??

    It wouldn't be much use if it wasn't possible, would it?

  • How to implement this algorithm ?

    Hello all,
    can u help me in implementing the following algorithm in java?
    1.suppose we start with a single pixel p and wish to expand from that seed pixel to fill a coherent region. lets define a similarity measure s(i,j) such that it produces a high result if pixels i and j are similar and a low one otherwise.
    first, consider a pixel q adjacent to pixel p. we can add pixel q to pixel p's region if S(p,q)>T for some threshold T. we can the proceed to the othr neighbors of p and do likewise.The process will continue till all the pixels in the image are labelled or belong to one region or the other.

    You may want to look at the various Connected components algorithms out
    there. These (tend to) recursively search the neighbours of the seed
    pixel and check for similarity. If the neighbours are similar to the
    seed they are marked as being in the same region. These algorithms can in general be made to run using a stack and while loop rather then using recursion (which on large images can get you into memory trouble very rapidly).
    A basic algorithm does the following
    create a second image containing ints. This image is the output from the algorithm. different regions have different integer numbers assigned to them. Ensure all pixels have -1 as their value.
    from your seed pixel check each of its neighbours in turn
    // the output image of integers
    private Image output;
    // the input image to process
    private Image input;
    // origin of the image is in the top left
    // assuming input image is greyscale and getPixel() / setPixel()
    // return Pixel objects. regionvalue should be greater then 0
    public void processPixel(int x, int y, Pixel compareTo, int regionValue)
       // am I similar to the pixel passed in
       // if so set my corresponding pixel in the output image
       if(isSimilar(input.getPixel(x,y),compareTo))
          output.getPixel(x,y).setGreyValue(regionValue);
       } else
          // i am not similar so bail out at let the caller check its
          // other neighbours
          return;
       //check north
       if( output.getPixel(x,y-1).greyValue() == -1)  // -1 means that its not been processed
          // this compares new pixel to this pixel
          processPixel(x,y-1,input.getPixel(x,y), regionValue);
       //check north east
      if( output.getPixel(x+1,y-1).greyValue() == -1)  // -1 means that its not been processed
          // this compares new pixel to the seed pixel
          // achives a different goal then the search for north given above
          // choose which goal suits you best
          processPixel(x+!,y-1,compareTo, regionValue);
       // check east
       //check south east
        //check north west
    // nope you are not mistaken all 8 neighbours may need to be checked if
    //  processing a greyscale image.
        return;
    }matfud

  • How to implement 3DES algorithm in Hardaware

    Help !!!
    I am getting poor perfomance in implemeting 3DES algorithm by code, which i need to improve lot.
    Can i implement it using hardware. If yes HOw? please help ...
    thanks.

    If you can use JNI the problem is very simple to solve. Write a JNI function (in C) that calls some C/Assembly implementation of TripleDES. You must deploy a .DLL (WIndows) or .SO (Unix) with your app.
    Read the Sheng Liang's book, downloadable from ftp://ftp.javasoft.com/docs/specs/jni.pdf , and the JNI specification in Sun's site.
    The speediest way is to make your JNI function handle the file reading, writing and encrypting (pass only the file names and the key, or password).
    The interface between Java and C via JNI is slow and if you simply define a JNI function that receives byte arrays, encrypt them and returns encrypted byte arrays, you can have performance problems. If the byte array is too small, the Pure Java implementation could be even faster than your JNI solution.

  • General Ledger Account Custom Clearing - Implement Custom Algorithm

    Hi,
    We have a situation where we have a lot of entries that fall into a clearing account within the balance sheet.  These entries are currently being cleared manually, because to the best of my knowledge the Automatic Clearing Program F.13, cannot cater for the logic performed by the users manually clearing the account.
    The Entries in the clearing account do not simply conform to the criteria as defined in OB74.  I was wondering if anyone else has got any ideas no how we can implement a custom clearing routine with far more complex logic than F.13.  Will this likely be a custom ABAP program that i will need to write?
    Thanks,
    Steve

    ps has different tables and have different calculations done on them to extract the data, your best bet is to search help.sap for oco_om_nwa_1, nwa_2 extractor and go through the list on which extractor is brining in what. then create a cube or multiprivder to satisfy your need.

  • How to implement this algorithm with region growing ?

    hi,
    I would like to ask u to help me in developing code for the region growing segmentation algorithm for digital images.The algorithm perform
    1.Model I should use the average of the pixel(for each colorchanel,red-green-blue ) from the color I choose.
    2. Strating start by choosing an arbitrary seed pixel via 10X10 region and calculate the average of the region and compare it with neighbouring pixels.
    3. growing region is grown from the seed pixel by adding in neighbouring pixels that are similar , increasing the size of the region.
    4. stop when the growth of one region stops, then the program should try another direction. the growth is starting on the left and in the same direction as the rotating hands of a clock
    the whole process is stoped until the growth of all the direction stoped and choose a largest region with a bounding box. all the pixels in the bounding box is now similar.
    I really don't know , how can I do it?
    Please suggest the tips to develop or code if u have for this algorithm.
    Thanks for ur help

    Something you need to consider is what sort of data structure you will use to hold the result of a region that you are growing. One possibility is to keep a second black and white image that is simply a mask of the grown region, i.e. black in the areas that have been included and white in the areas not yet covered.
    You also need to determine a threshold for similarity. How close in color space must two pixels be in order that you consider them to belong to the same region. You will need a boolean function that compares two colors and returns true if they are similar.
    Finally, if you use a mask bitmap to indicate where you have been, you can proceed in the following sort of manner.
    You can sweep across the entire image array, first right to left, then top to bottom, then left to right, then bottom to top, cycling through these 4 directions until nothing changes.
    A single sweep will consist of a double nested for loop, one incrementing x and the other incrementing y. Inside the inner loop you are considering a single pixel at (x,y)
    So assume that you are sweeping from left to right, i.e. incrementing x
    You will be expanding the reagion at (x,y) only if
    a) mask(x-1,y) is black (i.e. the previous pixel is in the region.
    b) maks(x,y) is white (the current point is not in the region
    c) color of image at (x,y) is similar to color of region
    When you update the region you will
    a) color the mask at (x,y) black
    b) add the RGB from the image to TotalR,TotalG,TotalB in region
    c) increase point count for the region
    The point count for a region and the TotalR etc allow you to compute the average color of the region at any time. You can detect if a single pass changed anything by noticing if the pointCount changed between two passes
    This algorithm is not particularly efficient, because you keep sweeping over the entire array, but it is easy to comprehend and easy to code.
    Note: the hard part is determining a decent threshold for color similarity. everything else is very straight forward.
    Enjoy!

  • Enhancement request: Improve override/implement detection algorithm

    Hello JDeveloper team,
    JDeveloper has some problem detecting a method is implementing an interface when generics are used.
    Example:
    1. Create the following
    public class MyStrangeMap implements Map<String, Map<String, String>>
    }2. JDeveloper tells you that you need to implement some methods, use JDeveloper to generate them.
    3. Notice most methods carry the up arrow telling you that you're implementing the method from the interface. However methods put and putAll won't for some obscure reason, probably involving the wildcard usage.
    Thanks,
    ~ Simon

    I just tried this in the newly-released JDeveloper 11g Tech Preview 2 release, and both for override and for implementing interface it brought along the throws clause as you are asking.
    Try downloading this new tech preview 2 release and please let us know if this addresses your request, or if we're still missing a case.
    Thanks.

  • New to JCE

    Hi,
    I am new to JCE. I have a RSA certificate. I dont know how can I use that to dncrypt the data that I send and decrypt the data that I receive. I need some code help please.

    Certificates are not used to decrypt. A Certificate is a wrapper for a Public Key.. Public Key's are used for encryption. You need the associated private key for decryption...
    Now those are reversed for Signatures...
    To use pub/priv key encryption you will be dealing with the Cipher object. You do this, in your case, with the RSA algorithm. So using Cipher you need to get an Cipher object implementing RSA algorithm with an appropriate mode and padding.. Now RSA does not really support modes so in reality it is just an algorithm and a padding...
    Typically it would look like...
    Cipher c = Cipher.getInstance("RSA//PKCS1Padding");
    But the exact transformation string specifying algorithm/mode/padding that your provider uses is specific to the provider. Note: the SunJCE does not supply an RSA algorithm implementation for Cipher. You will need to download a third party provider and install it properly.. Something like BouncyCastle as an example...
    nce you have done that and you have figured out what transformation string to use in the above getInstance() call, you then need to init it.
    For encryption you use the PublicKey which in your case is the Certificate.
    c.init(Cipher.ENCRYPT_MODE, cert);
    For decryption you need to use the private key.. Private and public keys are typically stored in a keystore.
    KeyStore ks = KeyStore.getInstance("JCEKS");
    You will need to load the keystore...
    ks.load(new FileInputStream(keystorefile), passwd.toCharArray());
    Then you will need to locate your keys.
    Key privKey = ks.getKey(myAlias, keyPasswd.toCharArray());
    Likewise, you will need to get your certificate.
    Once you have both your Cert and Key loaded you can do your crypto magic.. But it sounds like you have a bunch to learn so.. Well this will give you a start...

Maybe you are looking for

  • Flakey LCD after adding thuderbolt drive

    I have the latest version 17" MBP.  I have been using the mini display adapter to DVI to run a Gateway HD Display LP2407.  It works fine, but I purchased a G-Tech thunderbolt drive (8TB) and have a thunderbolt cable going from the mini display.thunde

  • Profile picture automatically reverting back

    Did anyone notice that or is it something that has to be set up separetely? If profile picture for the contact is updated using social app after an hour or so it automatically reverts back to the old one. Spent good half an hour yesterday to updated

  • Variable to track position in timeline

    Hi guys, I am trying to create a variable in Actionscript 2 that will record the position in the timeline, so Flash knows the user's last position on the timeline. The first line in the mc is: var portfoliostate; On frame 20 of the timeline, I have t

  • TCP/IP Library

    Hello. I am searching for a commercial c++ TCP/IP library to be used on Solaris (both Intel and SPARC). Is anyone aware of any such libraries? Thanks in advance, Jim

  • Unknown Table in Function

    I need to select from a table within a function, for example: CREATE OR REPLACE FUNCTION get_RowCount(Tab_Name IN VARCHAR2) RETURN NUMBER AS v_Table VARCHAR2(25); v_RowCount NUMBER; BEGIN v_Table := Tab_Name; SELECT COUNT(*) INTO v_RowCount FROM v_Ta