sdsu.net
Class XorSocket

java.lang.Object
  |
  +--java.net.Socket
        |
        +--sdsu.net.XorSocket

public class XorSocket
extends java.net.Socket

This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines. Each input and output byte is Xor'ed with the byte mask provided in the constructor. This provides a very weak form of encryption.

Version:
1.0 14 Feb 1998
Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
Socket

Constructor Summary
XorSocket(byte mask)
          Creates an unconnected socket.
XorSocket(java.net.InetAddress address, int port, byte mask)
          Creates a stream socket and connects it to the specified port number at the specified IP address.
XorSocket(java.net.InetAddress address, int port, java.net.InetAddress localAddr, int localPort, byte mask)
          Creates a socket and connects it to the specified remote address on the specified remote port.
XorSocket(java.lang.String host, int port, byte mask)
          Constructor for class XorSocket.
XorSocket(java.lang.String host, int port, java.net.InetAddress localAddr, int localPort, byte mask)
          Creates a socket and connects it to the specified remote host on the specified remote port.
 
Method Summary
 void close()
           
 java.io.InputStream getInputStream()
          Returns an inputstream on the socket.
 java.io.OutputStream getOutputStream()
          Returns an outputstream on the socket.
 
Methods inherited from class java.net.Socket
getInetAddress, getLocalAddress, getLocalPort, getPort, getReceiveBufferSize, getSendBufferSize, getSoLinger, getSoTimeout, getTcpNoDelay, setReceiveBufferSize, setSendBufferSize, setSocketImplFactory, setSoLinger, setSoTimeout, setTcpNoDelay, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XorSocket

public XorSocket(byte mask)
          throws java.io.IOException
Creates an unconnected socket. Used in Socket factories.
Parameters:
mask - byte mask with which all input/output bytes are Xor'ed
Throws:
java.io.IOException - if an I/O error occurs when creating the socket.

XorSocket

public XorSocket(java.lang.String host,
                 int port,
                 byte mask)
          throws java.io.IOException
Constructor for class XorSocket.
Parameters:
host - the remote machine to connect to
port - the remote TCP port
mask - byte mask with which all input/output bytes are Xor'ed
Throws:
java.io.IOException - if an I/O error occurs when creating the socket.

XorSocket

public XorSocket(java.net.InetAddress address,
                 int port,
                 byte mask)
          throws java.io.IOException
Creates a stream socket and connects it to the specified port number at the specified IP address.
Parameters:
address - the IP address.
port - the port number.
mask - byte mask with which all input/output bytes are Xor'ed
Throws:
java.io.IOException - if an I/O error occurs when creating the socket.

XorSocket

public XorSocket(java.lang.String host,
                 int port,
                 java.net.InetAddress localAddr,
                 int localPort,
                 byte mask)
          throws java.io.IOException
Creates a socket and connects it to the specified remote host on the specified remote port. The Socket will also bind() to the local address and port supplied.
Parameters:
host - the name of the remote host
port - the remote port
localAddr - the local address the socket is bound to
localPort - the local port the socket is bound to
mask - byte mask with which all input/output bytes are Xor'ed
Throws:
java.io.IOException - if an I/O error occurs when creating the socket.

XorSocket

public XorSocket(java.net.InetAddress address,
                 int port,
                 java.net.InetAddress localAddr,
                 int localPort,
                 byte mask)
          throws java.io.IOException
Creates a socket and connects it to the specified remote address on the specified remote port. The Socket will also bind() to the local address and port supplied.
Parameters:
address - the remote address
port - the remote port
localAddr - the local address the socket is bound to
localPort - the local port the socket is bound to
mask - byte mask with which all input/output bytes are Xor'ed
Throws:
java.io.IOException - if an I/O error occurs when creating the socket.
Method Detail

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns an inputstream on the socket. All bytes in the stream are Xor'ed with the sockets Xor mask;
Throws:
java.io.IOException - if an I/O error occurs.
Overrides:
getInputStream in class java.net.Socket

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Returns an outputstream on the socket. All bytes in the stream are Xor'ed with the sockets Xor mask;
Throws:
java.io.IOException - if an I/O error occurs.
Overrides:
getOutputStream in class java.net.Socket

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.net.Socket