
public class TextObject {

	char T [];
	int n;
	
	public TextObject( String s ){
		T = s.toCharArray();
		n = s.length();
	}
	
	public String string() {
		return new String( T );
	}
	
	public void shift( int c ) {
	
	for( int i= 0; i < n; i++ )
		T[i] = (char) ((int) T[i] + c);
	
	}
	
	public void shift2( int a ) {
	
	for( int i= 0; i < n; i++ ) {
		int x = (int) T[i];
		if ((x >= 65) && (x <= 90)) {
			x -= 65;
			x += a;
			x %= 26;
			x += 65;	
		}
		if ((x >= 97) && (x <= 122)) {
			x -= 97;
			x += a;
			x %= 26;
			x += 97;	
		}
		T[i] = (char) x;
		}
	
	}
		
    public void permute( String mapString ) {
	char mapArray [];
	mapArray = mapString.toCharArray();
	for( int i= 0; i < n; i++ ) {
	    int x = (int) T[i];
	    if ((x >= 97) && (x <= 122)) {  // char is 'a'...'z' 
		x -= 97;  // turn it into 0..25
		T[i] = mapArray[x]; // then substitute mapArray[x] for T[i]
	    }  // if
	} // for
    } // permute

    public void inversePermute( String mapString ) {
	char mapArray [];
	mapArray = mapString.toCharArray();
	for( int i= 0; i < n; i++ ) {
	    int x = (int) T[i];
	    if ((x >= 65) && (x <= 90)) {  // char is 'A'...'Z' 
		x -= 65;  // turn it into 0..25
		int j = 0;
		while( (j < 26) && (T[i] != mapArray[j]) )
		    j++;
		if (j < 26) // T[i] is mapArray[j]
		    T[i] = (char) (j+97); // then make the inverse substitution
	    }  // if
	} // for

    } // permute




}


